Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

SEMESTER:1: FINAL EXAMINATION

SPECIALTY: BTECH LEVEL: 3


COURSE TITLE: PROGRAMMING USING COURSE
PYTHON A CODE:
SEIT413A
AUTHORISED DOCUMENTS: YES  or NO  Time: 3 Hours Lecturer Name’s: AZOBOU KIADJEU CEDRIC

Instructions
1. The answers must be clear as possible to avoid any misunderstanding.
2. Any types of documents rather than the ones given by the invigilators are prohibited
3. In the MCQ part, each question has one (01) and only one good answer. Draw a table with 02 entries one for
question number and the other one for the letter corresponding to your good answer.
4. In the open answer questions, give a clear answer for each question with the maximum details according to the
total number of marks given
5. In the case study, your answers need to be oriented on practice. Give answers that can permit a technician to
achieve the goal. not just for the comprehension.

SECTION A: GENERAL QUESTIONS (50 marks)


PART 1: MCQ 20 Marks
1. Which type of Programming does Python support?
a. Object-oriented programming
b. Structured programming
c. Functional programming
d. All of the mentioned
2. Python language falls in which type of language
a. Semi-compiler language
b. Compiler language
c. Interpreted language
d. None of the above
3. Is Python case sensitive when dealing with identifiers?
a. No
b. Yes
c. Architecture dependent
d. Operating system dependent
4. Which of the following is the correct extension of the Python file?
a. .python
b. .py
c. .pl
d. .p
5. All keywords in Python are in _________
a. Capitalize
b. Lower case
c. Upper case
d. None of the mentioned
6. What will be the value of the following Python expression?
4 + 3 % 5
a. 7
1/5
b. 2
c. 4
d. 1
7. Which of the following is used to define a block of code in Python language?
a. Indentation
b. Keys
c. Brackets
d. All of the mentioned
8. What will be the output of the following Python code?
i = 1
while True:
if i%3 == 0:
break
print(i)
 
i += 1

a. 1 2 3
b. Error
c. 1 2
d. None of the mentioned
9. What will be the output of the following Python expression if x=56.236??
a. 56.236
b. 56.23
c. 56.0000
d. 56.24
10. What will be the output of the following Python function?
len(["hello",2, 4, 6])

a. Error.
b. 6
c. 4
d. 3
11. Which function is called when the following Python program is executed?
f = foo()
print(f)
a. str()
b. format()
c. __str__()
d. __init__()
12. Which function is called when the following Python program is executed?
f = foo()
a. str()
b. __str__()
c. init()
d. __init__()
13. To add a new element to a list we use which Python command?
a. List1.addEnd(5).
b. List1.addLast(5)
2/5
c. List1.append(5)
d. List1.add(5)
14. What will be the output of the following Python program?
i = 0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)

a. Error.
b. 0 1 2 0
c. 0 1 2
d. None of the above
15. What will be the output of the following Python code?
x = 'abcd'
for i in range(len(x)):
print(i)
a. 0 1 2 3
b. 1 2 3 4
c. a b c d
d. Error
16. In Python, a class is ___________ for a concrete object
a. A distraction.
b. A blueprint
c. A nuisance
d. An instance
17. The correct way to instantiate the following Dog class is:
class Dog:
def __init__(self, name, age):
self.name = name
self.age = age
a. Dog("Rufus", 3)
b. Dog.__init__("Rufus", 3)
c. Dog.create("Rufus", 3)
d. Dog()
18. With the object “buddy” we access to a class attribute, with
a. buddy.name;
b. buddyname;
c. buddy (name);
d. buddy__name
19. What’s the output of the following code snippet?

>>> class Dog:


2... def walk(self):
3... return "*walking*"

3/5
4...
5... def speak(self):
6... return "Woof!"
7...
8>>> class JackRussellTerrier(Dog):
9... def speak(self):
10... return "Arff!"
11...
12>>> bobo = JackRussellTerrier()
13>>> bobo.walk()
a. AttributeError:
b. object has no attribute 'walk';
c. *walking*
d. ; Arff!;
e. Woof!
20. In the above snippet what OOP principle is used in line 8
a. Class overriding;
b. Polymorphism;
c. Encapsulation;
d. Class overloading;
e. Inheritance

PART 2: OPEN ANSWER QUESTIONS 30 Marks


1. Give 02 aspects in which Python language need to improve according to you 02 marks
2. Give 04 IDE or Code editor that can be used to write python code 02 marks
3. What is the difference between list and tuples in Python? compare them on mutability and
syntax aspects 02 marks
4. What are the common built-in data types in Python? Give four (04) of them with a description
of data it contains 02 marks
5. In a python code, give a rule to identify: 02 marks
a. A local variable
b. A global variable
c. A private class property
d. A protected class property
6. What is “django” in python? 02 marks
7. Give the command used to create a new Django project 02 marks
8. Give in few words what the following libraries can be used for? 02 marks
a. Pygame
b. Tkinter
c. Seaborn
d. Numpy
9. How to install Python on Windows and set path variable? 02 marks
10. Give in 02 lines a python code that can be used to generate random numbers 02 marks
11. What is a lambda function? 02 marks
12. Explain the keyword “pass” in Python 02 marks
13. Which package is used by “pip” to setup and install another package? 02 marks
4/5
14. Give one sentence to explain the following “pip” command? 02 marks
a. Pip install
b. Pip uninstall
c. Pip show
d. Pip list
15. Python is a language suitable for “web scraping”. what do you understand by web scraping? 02
marks

Section B: PROBLEMS (20 marks)


A fraction in arithmetic is a number numerator divided by a denominator. In a simple fraction,
both are integers. A fraction is proper when the numerator is less than denominator and improper if
numerator is greater than the denominator. Any fraction can be written in decimal form by carrying
out the division of the numerator by the denominator. But in original form it is written “a/b” where a
and b are respectively numerator and denominator. In that original form notation, a fraction should
be in irreducible form mean the GCD (Greatest Common Divisor) of a and b should be 1. If not, the
fraction needs to be simplified. This simplification is done by dividing both numerator and
denominator by the GCD of the 02 numbers.
In this problem, our ambition is to build a calculator of fractions to help first cycle secondary
school students. To achieve the goal, we decide to first of all write a class “Fraction” to model a
fraction with the operation that we can applied on it.
Note: Comment your code to avoid any misunderstanding.
1. Write the python code for the Fraction class with a constructor that allow a user to define a
fraction with string value (such that 2/3) or with 02 integers values . 04 marks
2. Write a public method without argument named “isProper” that return 1 if the “self” fraction is
proper and 0 if not 02 marks
3. Write a private method named “ComputeGCD” without argument that compute the GCD of the
numerator and denominator of a fraction 03 marks
4. Write a public method without argument named “Simplify” which return the simplify version
of the “self” fraction. 02 marks
5. Write a public method without argument named “decimal” that return the decimal value of the
“self” fraction 02 marks
6. Write a public method that take on fraction in argument named “addFraction” and return the
product of this fraction with the “self” fraction. Ensure that the result must be irreducible. 04
marks
7. Write a small code that can be executed to display a window (GUI) with the title “my first
window in python”. 03 marks

5/5
6/5

You might also like