Lab 5
Lab 5
LAB # 05
OBJECTIVE: -
To become familiar with Python programming by using Integrated Development environment.
Exercise: -
A. Point out the errors, if any, and paste the output also in the following Python programs.
1. a = 500,b,c;
if ( a >= 400 ):
b = 300
c = 200
print( "Value is:", b, c )
if ( a >= 400 ):
b = 300
c = 200
print(type(number))
if number % 5 == 0:
print("HiFive")
else:
print("No answer")
2023F-BSE-088
Programming Fundamentals (SWE-102) SSUET/QR/144
print("grade = 'D'")
print("grade = 'C'")
print("grade = 'B'")
print("grade = 'A'")
else:
print("grade = 'F'")
1.Code Output
requested_topping = 'mushrooms'
if requested_topping != 'anchovies':
print("Hold the anchovies!")
2023F-BSE-088
Programming Fundamentals (SWE-102) SSUET/QR/144
2. Code Output
num = 3
if num >= 0:
print("Positive or Zero")
else:
print("Negative number")
3. Code Output
age = 15
if age < 4:
price = 0
elif age < 18:
price = 1500
else:
price = 2000
print("Your admission cost is Rs" + str(price) + ".")
Code Output
if no1 % 2 == 0:
else:
2. Write a program that asks for years of service and qualification from the user and calculates the salary
as per the following table:
Years of Service Qualifications Salary
>= 10 Masters 150,000
>= 10 Bachelors 100,000
< 10 Masters 100,000
< 10 Bachelors 70,000
2023F-BSE-088
Programming Fundamentals (SWE-102) SSUET/QR/144
Code Output
print("Salary = 150,000")
print("Salary = 100,000")
print("Salary = 100,000")
print("Salary = 70,000")
else:
3. Write an if-elif-else chain that determines a person’s stage of life, take input value for the
variable age, and then apply these conditions:
• If the person is less than 2 years old, print a message that the person is a baby.
• If the person is at least 2 years old but less than 4, print a message that the person is a toddler.
• If the person is at least 4 years old but less than 13, print a message that the person is a kid.
• If the person is at least 13 years old but less than 20, print a message that the person is a
teenager.
• If the person is at least 20 years old but less than 65, print a message that the person is an adult.
• If the person is age 65 or older, print a message that the person is an elder
Code Output
if age < 2:
print("Baby")
print("Toddler")
print("Kid")
2023F-BSE-088
Programming Fundamentals (SWE-102) SSUET/QR/144
print("Teenager")
print("Adult")
else:
print("Elder")
2023F-BSE-088