0% found this document useful (0 votes)
2 views1 page

Python Lab1 Basic

Uploaded by

mohammadaldhiny
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Python Lab1 Basic

Uploaded by

mohammadaldhiny
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

You might also like