COMP123 – INTRODUCTION TO PROGRAMMINGCOMP123
Deanship of Preparatory Year and Supporting Studies
Department of Computer
Homework
Introduction to Programming
(Individual)
Submission Date:
Total Marks 10
Weightage 10%
Until March 27, 2022 @ 11:59PM
Instructions:
i.
ii.
iii.
iv.
Read through the whole description below before starting with the homework.
You can refer to the links provided at the end of the homework for help.
It is strongly recommended that you try to solve the assignment yourself. Only if you are
stuck and absolutely cannot get an idea should you search your issue on
https://stackoverflow.com/
In case you use more than one python file (.py) to complete this homework, then zip your
files and upload the zip folder.
Q1. The following string data is given to you:
(3 Marks)
“Saudi Arabia traces its roots back to the earliest civilizations of the Arabian Peninsula. On September
23, 1932, King Abdulaziz Al-Saud established the Kingdom of Saudi Arabia, an Islamic state with Arabic
as its national language and the Holy Qur’an as its constitution.”
Save this data in a variable and write python code to extract the exact data from the string variable:
Note: For total characters in string see len()function.
1
COMP123 – INTRODUCTION TO PROGRAMMING
Q2. Create a variable of list data type, which stores the following data:
student name (string), student id (number), section number (string), subject (string), marks (float).
(3 Marks)
a) Write python code to generate exactly the following output:
Make sure you write your own data (your name, your ID and so on.). You can write any subject
name and marks.
b) Now add another value to your list, which is grade (string). Your new output should look like the
following:
Note: For adding grade to your list see append()function. Do not add grade value manually,
make sure you use append function. You can write any value for grade (A+, A, or B+).
2
COMP123 – INTRODUCTION TO PROGRAMMING
Q3. Write a python code that takes total marks as input from the user (integer or float) and calculates
the grade according to the following table:
(4 Marks)
Grade
Total Marks
A+
95 or above
A
90 – 94
B+
85 – 89
B
80 – 84
C+
75 – 79
C
70 – 74
D+
65 – 69
D
60 – 64
F
less than 60
Note: The total marks entered by the user are rounded to the nearest integer before assigning them a
grade. For rounding marks see round()function.
For example:
Reference Material:
References related to Python for Everybody Book:
https://www.py4e.com/lessons/
https://www.py4e.com/lessons/lists
External References:
https://www.learnpython.org/
https://www.w3schools.com/python/default.asp
3