Final Paper Resit Exam For Python Programming

You might also like

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

SEMESTER:1: RESIT 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. What is the maximum possible length of an identifier?
a. 16
b. 32
c. 64
d. None of these above
2. Who developed the Python language?
a. Zim Den
b. Guido van Rossum
c. Niene Stom
d. None of the above
3. Which character is used in Python to make a single line comment?
a. #
b. //
c. <!--
d. >//
4. Which of the following statements is correct regarding the object-oriented programming
concept in Python?
a. Classes are real-world entities while objects are not real
b. Objects are real-world entities while classes are not real
c. Both objects and classes are real-world entities
d. All of the above
5. Which of the following declarations is incorrect?
a. _x = 2
b. __x=2
c. __x__=2
d. None of the mentioned
6. Which of the following is not a keyword in Python language?
a. val
b. raise
1/3
c. try
d. with
7. Which of the following words cannot be a variable in python language?
a. _val
b. val
c. try
d. __try
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
b. Error
c. 1 2 3
d. None of the mentioned
9. Which statement is correct?
a. List is mutable & tuple is immutable
b. List is immutable & tuple is mutable
c. Both are mutable
d. Both are immutable
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 one of the following is not a python’s predefined data type?
a. list
b. tuple
c. dictionary
d. class
13. To add a new element to a list we use which Python command?
a. List1.addEnd(5).
b. List1.addLast(5)
c. List1.append(5)
d. List1.add(5)
14. What will be the output of the following Python program?

2/3
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. What’s the output of the following code snippet?

>>> class Dog:


2... def walk(self):
3... return "*walking*"
4...
5... def speak(self):
6... return "Woof!"
7...
8>>> class JackRussellTerrier(Dog):
9... def speak(self):
10... return "Arff!"
11...

3/3
12>>> bobo = JackRussellTerrier()
13>>> bobo.walk()
a. AttributeError:
b. object has no attribute 'walk';
c. *walking*
d. Arff!
e. Woof!
19. What’s the output of the following code snippet?
>>> class Dog:
2... def walk(self):
3... return "*walking*"
4...
5... def speak(self):
6... return "Woof!"
7...
8>>> class JackRussellTerrier(Dog):
9... def talk(self):
10... return super().speak()
11...
12>>> bobo = JackRussellTerrier()
13>>> bobo.talk()
a. AttributeError:
b. object has no attribute 'walk';
c. *walking*;
d. Arff!;
e. Woof!
20. Given the following code snippet, which of the following REPL output is correct?
class Dog:
def __init__(self, name, age):
self.name = name
self.age = age

class JackRussellTerrier(Dog):
pass

class Dachshund(Dog):
pass

class Bulldog(Dog):
pass
miles = JackRussellTerrier("Miles", 4)
buddy = Dachshund("Buddy", 9)
jack = Bulldog("Jack", 3)
4/3
jim = Bulldog("Jim", 5)
a. >>> isinstance(miles, Dog)
False
b. >>> isinstance(jack, Dachshund)
False
c. >>> isinstance(buddy, Bulldog)
True
d. >>> isinstance(miles, Bulldog)
False
e. >>> isinstance(miles, Dog)
True

PART 2: OPEN ANSWER QUESTIONS 30 Marks


1. What is Polymorphism in oop? 02 marks
2. What is __init__? 02 marks
3. What is a lambda function? 02 marks
4. What is self in Python? 02 marks
5. How can you generate random numbers in Python? 02 marks
6. Which function can you used to randomize the items of a list in place in Python? 02 marks
7. What does “*args” mean as argument of a function in python and why would we use it? 02 marks
8. Let us consider the following python code: 03 marks
stg='AB/CD'
t = len(stg)
x = stg.split('/')
a. Give the value of t and x
b. What is the type of x variable?
9. Explain //, % and * *operators in python? 03 marks
10. About list in python, explain the meaning of the following function 03 marks
a. append
b. insert
c. extend
11. What is a python library? Give an example of python library used to build game software, data
analysis software and GUI (Graphical User Interface) 03 marks
12. Define in python what is a module: 01 mark
13. What are global, protected and private attributes in Python? Precise how to define it 03 marks

5/3
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 . 05 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 04 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”. In this window, add a text input and a button. 03 marks

6/3

You might also like