End of Course Exam

Test your python basics knowledge with this Exam
Author

Juma Shafara

Published

August 12, 2024

Keywords

python, quiz, python quiz, dataidea, data science

Photo by DATAIDEA

Objectives

  • Write and run Python code
  • Practice problem solving using Python code.
  • Learn how to detect programming errors through program testing.
  • Correct/fix syntax errors and bugs.

Prerequisites

  • Students are expected to be familiar with a text editor.
  • A basic understanding of running and linking in concept.
  • Knowledge in area such as Python language syntax, input output function is recommended.

Questions

  1. Write a Python program to display the following text on the screen.
DATAIDEA
Sir Apollo Kagwa Road,
Kampala,
Uganda
-------------------
www.dataidea.org
# your solution
  1. Write a program to assign the number 34.5678 to a variable named “number” then display the number rounded to the nearest integer value and next the number rounded to two decimal places.
# your solution
  1. Write a program to identify whether a number input from the keyboard is even or odd. If it is even, the program should display the message “Number is even”, else it should display “Number is odd”.
# your solution
  1. Write a program to display the student’s grade based on the following table:
Marks Grade
>= 75 A
> 50 and <=75 B
> 25 and <=50 C
<= 25 D
# your solution
  1. Write a program to convert a given character from uppercase to lowercase and vice versa.
# your solution
  1. Write a program which accepts a number (an amount of money to be paid by a customer in rupees) entered from the keyboard. If the amount is greater than or equal to 1000 rupees, a 5% discount is given to the customer. Then display the final amount that the customer has to pay.
# your solution
  1. A car increases it velocity from u ms-1 to v ms-1 within t seconds. Write a program to calculate the acceleration.
# your solution
  1. Write a program to input a temperature reading in either Celsius(c) or Fahrenheit(f) scale and convert it to the other scale. The temperature reading consists of a decimal number followed by letter ”F” or ”f” if the temperature is in Fahrenheit scale or letter ”C” or ”c” if it is in Celsius scale. You may use a similar format for the output of the program. Note: c = 5( f − 32) / 9
# your solution
  1. Develop a simple calculator to accept two floating point numbers from the keyboard. Then display a menu to the user and let him/her select a mathematical operation to be performed on those two numbers. Then display the answer. A sample run of you program should be similar to the following:
Enter number 1: 20
Enter number 2: 12
Mathematical Operation
-----------------------------------
1 - Add
2 - Subtract
3 - Multiply
4 - Divide
-----------------------------------
Enter your preference: 2
Answer : 8.00
# your solution
  1. Write a program to display all the integers from 100 to 200.
# your solution
  1. Write a program to calculate the sum of all the even numbers up to 100.
# your solution
  1. Write a program to compute the sum of all integers form 1 to 100.
# your solution
  1. Write a program to calculate the factorial of any given positive integer.
# your solution
  1. Write a program to compute the sum of all integers between any given two numbers. In this program both inputs should be given from the keyboard.
# your solution
  1. What would happen if we enter -1 as the number of times to loop in Program-5.4? Modify Program-5.4 so that it works only for positive integers.
# your solution
  1. Write a program to display the following symbol pattern:
*
**
***
****
*****
******
# your solution
  1. Write a program to display the message “Hello World!” 10000 times. The program should allow users to terminate the program at any time by pressing any key before it displays all the 10000 messages.
# your solution
  1. Write a program to display a sine table. The program should display all the sine values from 0 to 360 degrees (at 5 degrees increments) and it should display only 20 rows at a time
# your solution
  1. Write a program to store marks of 5 students for 5 subjects given through the keyboard. Calculate the average of each students marks and the average of marks taken by all the students
# your solution
  1. Write a program to calculate the circumference and area of a circle given its radius. Implement calculation of circumference and areas as separate functions.
# your solution
  1. Write a program to read the file “my file.txt” which has the message:
Hello World!
This is my first file
# your solution
  1. Write a Python program to store the message “Introduction Python Programming” in a file named “message.txt”.
# your solution
  1. Write a program to display the following menu on the screen and let the user select a menu item. Based on the user’s selection display the category of software that the user selected program belongs to.
Menu
-----------------------------------
1 – Microsoft Word
2 – Yahoo messenger
3 – AutoCAD
4 – Java Games
-----------------------------------
Enter number of your preference:
# your solution
  1. Develop a simple telephone directory which saves your friends contact information in a file named directory.txt. The program should have a menu similar to the following:
----------------Menu-------------------------
1. Add new friend.
2. Display contact info.
3. Exit
------------------------------------------------
Enter menu number:

When you press “1” it should request you to enter following data:

---------New friend info--------
Name : Saman
Phone-No: 011-2123456
e-Mail : saman@cse.mrt.ac.lk

After adding new contact information it should again display the menu. When you press “2” it should display all the contact information stored in the directory.txt file as follows:

--------------Contact info---------------
Name            Tel-No          e-Mail
Kamala          077-7123123     kamala@yahoo.com
Kalani          033-4100101     kalani@gmail.com
Saman           011-2123456     saman@cse.mrt.ac.lk
-----------------------------------------
# your solution
  1. Given a date as a triplet of numbers (y, m, d), with y indicating the year, m the month (m = 1 for January, m = 2 for February, etc.), and d the day of the month, the corresponding day of the week f (f = 0 for Sunday, f = 1 for Monday, etc.) can be found as follows:
(a) if m < 3
(b) let m = m + 12 and let y = y - 1
(c) let a = 2m + 6 (m + 1) / 10
(d) let b = y + y/4 – y/100 + y/400
(e) let f 1 = d + a + b + 1
(t) let f = f 1 mod 7
(g) stop.

Write a program that will read a date and print the corresponding day of the week. All divisions indicated above are integer divisions.

# your solution
  1. Write a program to input a series of positive integers and determine whether they are prime. The program should terminate if a negative integer is given as the input. A prime number is a number that is divisible by only one and itself. However one is not considered a prime number.
# your solution
  1. Write a program to find out whether a given number is a perfect number. The program should terminate if a negative integer is given as the input. A perfect number is a number whose factors other than itself add up to itself.
# your solution
  1. Write a program to find and display the minimum and the maximum among 10 numbers entered from the keyboard. Use a single-dimensional array to store the numbers entered. The numbers can be non-integers. An example would be as follows:
Enter 10 numbers: 5 7.8 9.6 54 3.4 1.2 3 7 8.8 5
Minimum = 1.2
Maximum = 54
# your solution
  1. Suppose there are 4 students each having marks of 3 subjects. Write a program to read the marks from the keyboard and calculate and display the total marks of each student. Use a 2D (two-dimensional) array to store the marks. An example would be as follows:
Enter the marks of four students, on four rows:
50 60 80
60 75 90
30 49 99
66 58 67

Total marks of four students:
190
225
178
191
# your solution
  1. Write a program to read in two matrices A and B of dimensions 3×4 and 4×3 respectively, and compute and display their product AB (of dimensions 3×3). Assume that the elements of the matrices are integers. Use functions to while implementing this program.
# your solution

Congratulation!

Congratulations on completing this Python Fundamentals Course

What’s on your mind? Put it in the comments!

Back to top