FEDERAL COLLEGE OF FORESTRY JOS
SECOND SEMESTER 2023/2024 ACADEMIC SESSION
COM 311: PROGRAMMING LANGUAGE USING PYTHON
HND I AEM, CPT, HLT, PMT & AGT TIME 2:30HRS UNIT(S) 4.0
INSTRUCTION: ATTEMPT ONE QUESTION AND ANY FOUR, EACH OF THE OTHER
FOUR CARRY EQUAL MARKS.
QUESTION 1
A. Is Python a case sensitive language? Justify your answer (2marks)
B. State the name of the following programming symbol (4 Marks)
i. : ii. [] iii. () iv.{} v. ; vi _ vii. % vii. *
C. Write a python program to print Student Bio Data:
Test Data Name: Forestry, Mat no: CFJ/Forestry, : Green, and Department: All (4
Marks)
D. Expand IDE and list 4 IDE for Python programming (2 marks)
QUESTION 2
A. State 10 keywords in python programming (4 marks)
B. Expand any 4 built in Data type (3 Marks)
C. Write a python program to convert temperature in Celsius and Fahrenheit
Formula: C/5 = F-32/9 where c = temperature in Celsius and f = temperature in Fahrenheit
(5 marks)
QUESTION 3
A. List and Explain 2 Different Types of Comments in Python? (2 marks)
B. Python is a popular programming language State 5 Uses of python (2 marks)
C. Write python Function to find the maximum of three number (5 marks)
D. Give two Difference between set and list data type (3 marks)
QUESTION 4
A. What is NumPy in python (2 marks)
B. How do you install NumPy in python (2 marks)
C. Write a NumPy program to get the version and show NumPy build configuration (2 marks)
D. Expand Operator in python and give each four examples ((4 marks)
QUESTION 5
A. What is difference between NumPy and pandas (2 marks)
B. Define Pandas (2 marks)
C. State 4 python syntax compare to other programing language (2 marks)
D. State key functionalities of Pandas (2 marks)
E. Write a Pandas program to create and display one dimensional array like object contain an array
of data (4 marks)
Sample data: 2,4,6,8,10
QUESTION 6
A. What is the output of the following python syntax? Let x = 7, y = 9 (5 marks)
i.y = y % 7 ii. x =+ 2 iii. y++ iv. y % x v. - - x
B. State 3 application of python (2.5 marks)
C. State the key characteristic of python variable (2.5 marks)
D. State the syntax to declare comment (2 marks)
QUESTION 7
A. Give 3 naming rules in python (3 marks)
B. Give 3 Example of platform which python can work on (3 marks)
C. Who Invented Python and in which year (2 marks)
D. Write a pandas program to create a dataframe from a dictionary and display it. (4 marks)
SAMPLE DATA: {'X':[78,85,96,80,86], 'Y':[84,94,89,83,86],'Z':[86,97,96,72,83]}
QUESTION 8
A. Define the following (9 marks)
i. python
ii. variable
iii. Data type
iv. Operator
v. Set
vi. Truple
B. State the key characteristic of python variable (3 marks)
FEDERAL COLLEGE OF FORESTRY JOS
SECOND SEMESTER 2023/2024 ACADEMIC SESSION
COM 311: PROGRAMMING LANGUAGE USING PYTHON
HND I AEM, CPT, HLT, PMT & AGT TIME 2:30HRS UNIT(S) 4.0
INSTRUCTION: ATTEMPT ONE QUESTION AND ANY FOUR, EACH OF THE OTHER
FOUR CARRY EQUAL MARKS.
Marking scheme
QUESTION 1
A. Is Python a case sensitive language? Justify your answer (2marks)
Python is case sensitive language. In Python ‘A’ and ‘a’ both value are treated as different
because both have different ASCII/UNICODE value.
B. State the name of the following programming symbol (4 Marks)
i. = Assignment
ii. [] = Square bracket
iii. ()= open bracket
iv.{}= Curly braces
v. ; = terminator
vi _ = under score
vii. % module
viii. * Asterisk
C. Write a python program to print Student Bio Data:
Test Data Name: Forestry, Mat no: CFJ/Forestry, Gender: Green, and Department: All
(4 Marks)
String Name = “ Forestry”
String Mat_no = “ CFJ/Forestry”
String Gender = “ Green”
String Department = “ All “
Print(Name)
Print(Mat_no )
Print(Gender)
Print(Department)
C. Expand IDE and list 4 IDE for Python programming (2 marks)
Integrated Development Environment eg Thonny, Pycharm, Netbeans or Eclipse
QUESTION 2
A. State 10 keywords in python programming (4 marks)
Print, if, int, float, else, and, or, not, True, False, None
B. Expand any 4 built in Data type (3 Marks)
List, set, Triple and Dictionary
List are used to store multiple item in a single variable
. Set : Sets are used to store multiple items in a single variable. A set is a collection which
is unordered, unchangeable*, and unindexed.
Truple: Tuples are used to store multiple items in a single variable. A tuple is a collection
Dictionary are used to store data values in key value pair
C. Write a python program to convert temperature in Celsius and Fahrenheit
Formula: C/5 = F-32/9 where c = temperature in Celsius and f = temperature in Fahrenheit
(5 marks)
import math
radius = float(input("Enter the radius of the circle: "))
except ValueError:
print("Invalid input. Please enter a numerical value for the radius.")
exit()
area = [Link] * (radius ** 2)
print("The area of the circle with radius", radius, "is:", area)
QUESTION 3
A. List and Explain 2 Different Types of Comments in Python? (2 marks)
Single line and multiple line comment
Single-line comments: These comments begin with a hash symbol (#) and extend to
the end of the line
Multi-line comments (achieved through consecutive single-line
comments): While Python does not have a specific multi-line comment syntax
like /* ... */ in some other languages, multi-line explanations can be created by
placing a # at the beginning of each line intended as a comment.
B. Python is a popular programming language State 5 Uses of python (2 marks)
i. web development (server-side),
ii. software development,
iii. mathematics,
iv. system scripting.
C. Write python Function to find the maximum of three number (5 marks)
def find_max_of_three_conditional(num1, num2, num3):
if num1 >= num2 and num1 >= num3:
return num1
elif num2 >= num1 and num2 >= num3:
return num2
else:
return num3
result = find_max_of_three_conditional(10, 25, 15)
print(f"The maximum number is: {result}")
D. Give two Difference between set and list data type (3 marks)
Lists are mutable, meaning their elements can be changed, added, or removed
after creation. While Sets are also mutable in terms of adding or removing
elements, but the elements themselves must be immutable (e.g., numbers, strings,
tuple
QUESTION 4
A. What is NumPy in python (2 marks)
Numpy, short for numerical python, is a fundamental open-source library in python for
scientific computing. It provides a powerful and efficient way to work with large, multi-
dimensional arrays and offers a vast collection of high-level mathematical functions to
operate on these arrays.
B. How do you install NumPy in python (2 marks)
C. Write a NumPy program to get the version and show NumPy build configuration (2 marks)
USING PYTHON'S __VERSION__ ATTRIBUTE:
D. Expand Operator in python and give each four examples ((4 marks)
Operators are used to perform operations on variables and values.
Arithmetic Operators +,-, *
Assignment Operators =
Comparison Operators >, < , <=, >=
Logical Operators and or not
QUESTION 5
A. What is difference between NumPy and pandas (2 marks)
1. Numpy arrays are homogeneous (single data type), while pandas dataframes can
handle heterogeneous data types across columns.
2. Numpy is optimized for array-based numerical data, while pandas excels with
labeled, tabular data.
3. Pandas offers a richer set of tools for data cleaning, manipulation, and analysis of
structured data, including handling missing values and various data
transformations. Numpy focuses on core numerical operations.
B. Define Pandas (2 marks)
Pandas is an open-source python library designed for data analysis and manipulation. It
provides powerful and flexible data structures, primarily the dataframe and series, which
make working with structured data both intuitive and efficient.
C. State 4 python syntax compare to other programing language (2 marks)
Answer:
i. Python was designed for readability, and has some similarities to the English language with
influence from mathematics.
ii. Python uses new lines to complete a command, as opposed to other programming languages
which often use semicolons or parentheses.
iii. Python relies on indentation, using whitespace, to define scope; such as the scope of loops,
functions and classes. Other programming languages often use curly-brackets for this purpose
D. State key functionalities of Pandas (2 marks)
Answer
Data loading and exporting: reading and writing data from various formats like csv, excel, sql
databases, json, and more.
Data cleaning and preprocessing: handling missing data, removing duplicates, and transforming
data types.
Data manipulation: filtering, sorting, merging, joining, and reshaping data.
Data aggregation and grouping: performing operations like groupby to analyze data based on
categories and calculate summary statistics.
E. Write a Pandas program to create and display one dimensional array like object contain an
array of data (4 marks)
Sample data: 2,4,6,8,10
QUESTION 6
B. What is the output of the following python syntax? Let x = 7, y = 9 (5 marks)
i.y = y % 7 ii. x =+ 2 iii. y++ iv. y % x v. - - x
Answer
0 4 5 2 6
B. State 3 application of python (2.5 marks)
Answer
web development (server-side),
software development,
mathematics,
system scripting.
C. State the key characteristic of python variable (2.5 marks)
Answer
Dynamic Typing:
Assignment:
D. State the syntax to declare comment (2 marks)
Answer
Creating a Comment
Comments starts with a #, and Python will ignore them:
Example
#This is a comment
print("Hello, World!")
QUESTION 7
A. Give 3 naming rules in python (3 marks)
Answer:
Variable names must start with a letter or an underscore.
They cannot start with a number.
They can only contain alpha-numeric characters and underscores.
Variable names are case-sensitive (age, Age, and AGE are different variables).
They cannot be any of Python's keywords (e.g., if, for, while).
B. Give 3 Example of platform which python can work on (3 marks)
Answer : Windows, Mac, Linux, Raspberry Pi, etc).
C. Who Invented Python and in which year (2 marks)
Answer: It was created by Guido van Rossum, and released in 1991
D. Write a pandas program to create a dataframe from a dictionary and display it. (4 marks)
SAMPLE DATA: {'X':[78,85,96,80,86], 'Y':[84,94,89,83,86],'Z':[86,97,96,72,83]}
Answer
QUESTION 8
E. Define the following (9 marks)
i. python : Python is a popular programming language. It was created by Guido van
Rossum, and released in 1991
ii. variable : Variables in Python are containers used for storing data values.
iii. Data type : Data type of data which is used in the program.
iv. Operator : operators are symbols that are used to perform mathematical or logical
manipulations
v. Set : Sets are used to store multiple items in a single variable. A set is a collection which
is unordered, unchangeable*, and unindexed.
vi. Truple: Tuples are used to store multiple items in a single variable. A tuple is a collection
which is ordered and unchangeable.
F. State the key characteristic of python variable (3 marks)
Key characteristics of Python variables:
Dynamic Typing:
Python variables can hold values of different data types (e.g., integers, strings, lists) during the program's
execution.
Assignment:
Variables are created using the assignment operator (=). For example, x = 10 assigns the value 10 to the
variable x.