Programming Fundamentals
Python – Lab 1
Q1: Write a Python program that prompts the user to enter information about a
student (Name, Major and Mark), and print them in the following format.
Name Major Mark
---- ----- ----
Ali CS 99
Solution:
name = input ('Enter the first student name')
major = input ('Enter the first student major')
mark = input ('Enter the first student mark')
print ('Name', 'Major', 'Mark', sep='\t')
print ('----', '-----', '----', sep='\t')
print (name, major, mark, sep='\t')
Q2: Write a Python program that prompts the user to enter a width and length of a
rectangle, and calculates its area and circumference.
Hint:
Rectangle area = length * width
Rectangle Circumference = 2 (length + width)
Solution:
length = float (input ('Enter the length of the rectangle'))
width = float (input ('Enter the width of the rectangle'))
area = width * length
circum = 2 * (width + length)
print ('Area = ', area)
print ('Circumference = ', circum)
Q3: Write a Python program that reads the sides of a cube and calculates its volume.
Hint: Volume = width * length * height