0% found this document useful (0 votes)
22 views

Lab 5

The document discusses exercises from a programming fundamentals lab. It contains Python code examples with errors and expected corrections. It also provides multiple choice questions about Python code blocks and their expected output.

Uploaded by

m.shayan.8401
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Lab 5

The document discusses exercises from a programming fundamentals lab. It contains Python code examples with errors and expected corrections. It also provides multiple choice questions about Python code blocks and their expected output.

Uploaded by

m.shayan.8401
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Programming Fundamentals (SWE-102) SSUET/QR/144

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 )

Error in given code.


500, b, c is the error.
Correct Code: Output:
a=b=c = 500;

if ( a >= 400 ):

b = 300

c = 200

print( "Value is:", b, c )

2. &number = eval(input("Enter an integer: "))


print(type(number))
if number % 5 == 0
print("HiFive")
else
print("No answer")

Error in given code.

& and no use of ‘:’ after it and else.

Correct Code: Output:

number = eval(input("Enter an integer: "))

print(type(number))

if number % 5 == 0:

print("HiFive")

else:

print("No answer")
2023F-BSE-088
Programming Fundamentals (SWE-102) SSUET/QR/144

3. if score >= 60.0


grade = 'D'
elif score >= 70.0
grade = 'C'
elif score >= 80.0
grade = 'B'
elif score >= 90.0
grade = 'A'
else:
grade = 'F

Error in given code.

No print Function and no use of ‘:’ .


Correct Code: Output:

score = eval(input("Enter Your Score::"))

if score >= 60.0 and score <= 69.0 :

print("grade = 'D'")

elif score >= 70.0 and score <= 79.0 :

print("grade = 'C'")

elif score >= 80.0 and score <= 89.0 :

print("grade = 'B'")

elif score >= 90.0 and score <= 99.0 :

print("grade = 'A'")

else:

print("grade = 'F'")

B. What would be the output of the following programs:

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) + ".")

C. Write Python programs for the following:


1. Any integer is input through the keyboard. Write a program to find out whether it is an odd number
or even number.

Code Output

no1 = int(input("Enter a integer::"))

if no1 % 2 == 0:

print(no1,"is an even number")

else:

print(no1,"is an odd number")

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

ser = eval(input("Enter your years of service::"))

qual = input("Enter your Qualification::")

if (ser >= 10 and qual == "Masters"):

print("Salary = 150,000")

elif (ser >= 10 and qual == "Bachelors"):

print("Salary = 100,000")

elif (ser < 10 and qual == "Masters"):

print("Salary = 100,000")

elif (ser < 10 and qual == "Bachelors"):

print("Salary = 70,000")

else:

print("You Are not Qualified")

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

age = eval(input("Enter your age::"))

if age < 2:

print("Baby")

elif age==2 and age < 4:

print("Toddler")

elif age==4 and age < 13:

print("Kid")

2023F-BSE-088
Programming Fundamentals (SWE-102) SSUET/QR/144

elif age==13 and age < 20:

print("Teenager")

elif age==20 and age < 65:

print("Adult")

else:

print("Elder")

2023F-BSE-088

You might also like