Islamic University الجامعة اإلسالمية
Faculty of Computer and كلية الحاسب اآللي ونظم
Information Systems المعلومات
Student ID Student Name Signature
FINAL EXAMINATION
Section : □ 2290 □ 4506
Code : CCS 3074
Course : Introduction to Programming
Semester-Year : 2nd SEMESTER, 2023-24
Day-Date : Sunday – 26 May 2024
Start Time : 10:30 AM
Finish Time : 12:30 PM
General Information for Students:
Question CO Markss Marks
No. No. Assigned Awarded
1 1 2
2 2 6
3 3 6
4 4 5
5 5 7
6 6 6
7 7 8
Total 40
➢ Read and follow the instructions for each question carefully.
➢ Answer all the questions.
➢ Write your ID on each page
➢ Calculators are not allowed.
Islamic University الجامعة اإلسالمية
Faculty of Computer and كلية الحاسب اآللي ونظم
Information Systems المعلومات
[Link].1: Differentiate between Machine Language and High-Level Language. [2 Marks]
Student Name: ___________________________________ Student ID: ____________
Page 2 of 9
Islamic University الجامعة اإلسالمية
Faculty of Computer and كلية الحاسب اآللي ونظم
Information Systems المعلومات
[Link].2: Show the output of the following code segments: [2+2+2 marks]
a.
x = 2 Output:
print("x value before update:", x)
x+= 3
print("x value after update:", x)
b.
fname = "khalid" Output:
lname = "omar"
first = [Link]()
last = [Link]()
print(f"Full name: {first} {last}")
c.
age = 14 Output:
price = 400
if age < 18 and price > 200:
print("Ticket price:", (price/2))
else:
print("Ticket price:", price)
Student Name: ___________________________________ Student ID: ____________
Page 3 of 9
Islamic University الجامعة اإلسالمية
Faculty of Computer and كلية الحاسب اآللي ونظم
Information Systems المعلومات
[Link].3: [3 + 3 marks]
a. Write a Python program that asks the user to enter a message and how many times he wants
it printed then prints the message that many times separated by *.
Expected output:
Enter a message: Hello
How many times you want to print the message: 3
Hello*Hello*Hello*
b. Write a Python program that prompts the user to enter two integers (lower and upper
bound). The program should then print all the odd numbers between (and including) the lower
and upper bound.
Expected output:
Enter two numbers: 3, 12
3 5 7 9 11
Student ID: ______________________
Page 4 of 9
Islamic University الجامعة اإلسالمية
Faculty of Computer and كلية الحاسب اآللي ونظم
Information Systems المعلومات
[Link].4: Develop a python function called div, that applies division with reminder. The
function takes two integer numbers (dividend and divisor) as arguments and calculates and
returns the quotient and reminder of the division. [5 marks]
Expected behaviour:
q, r = div(16,3)
print("q is", q,"and r is", r) → q is 5 and r is 1
Student ID: ______________________
Page 5 of 9
Islamic University الجامعة اإلسالمية
Faculty of Computer and كلية الحاسب اآللي ونظم
Information Systems المعلومات
[Link].5: Analyze the following code to find 7 mistakes, circle each mistake. [7 marks]
1 scores = [86,56,94,97,74,48,67)
2
3 counter == 0
4 passing_score = 60
5
6 for i range(len(scores)):
7 if scores(i) >= passing_score
8 counter + 1
9
10 print("The number of students who passed the course is ", Counter)
Rewrite the lines which contain mistakes after fixing them.
Line
Fixing the error
number
Student ID: ______________________
Page 6 of 9
Islamic University الجامعة اإلسالمية
Faculty of Computer and كلية الحاسب اآللي ونظم
Information Systems المعلومات
[Link].6: Write python statements to perform the following operations: [6 marks]
1. Create a list to store the following values: Ahmad, Khalid, Hussain, Turki, Ahmad,
Othman.
2. Check if the list contains any element with the value Ahmad.
3. Find the index of the element with the value Turki.
4. Remove the element with the value Khalid.
5. Append an element with the value Muhammad to the end of the list.
6. Create a sub-list that contains only the first three elements of the original list.
Student ID: ______________________
Page 7 of 9
Islamic University الجامعة اإلسالمية
Faculty of Computer and كلية الحاسب اآللي ونظم
Information Systems المعلومات
[Link].7: [4 + 4 marks]
a. Define a Python class named Building to represent a building that contains:
• A data field called owner for the owner’s name.
• A data field called rooms for the number of rooms.
• A data field called address for the building’s address.
• An initializer that creates a building with the specified owner, number of rooms and
address.
• A method named changeOwner() that changes the owner’s name.
Student ID: ______________________
Page 8 of 9
Islamic University الجامعة اإلسالمية
Faculty of Computer and كلية الحاسب اآللي ونظم
Information Systems المعلومات
b. Write a test program that creates two Building objects
• building_1: with owner’s name Ayman, number of rooms 6 and the address
Sultanah.
• building_2: with owner’s name Kamal, number of rooms 8 and the address Salam.
• Change the owner of building_1 to be Hasan.
• Print the information of building_2
Student ID: ______________________
Page 9 of 9