0% found this document useful (0 votes)
318 views11 pages

Python Conditional Statements Lab

The document appears to be a lab report from the Computer Engineering Department at the Islamic University of Gaza. It includes 5 programming exercises: 1) a temperature conversion program using conditional statements; 2) tasks to solve independently and comment on, including comparing two numbers and determining the status of an average; 3) a program that checks for duplicate values; 4) a program to find the smallest of three integers without using the min function; and 5) rewriting conditional expressions as if/else statements and vice versa. The document also notes there is an error in one of the programs that cannot be fixed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
318 views11 pages

Python Conditional Statements Lab

The document appears to be a lab report from the Computer Engineering Department at the Islamic University of Gaza. It includes 5 programming exercises: 1) a temperature conversion program using conditional statements; 2) tasks to solve independently and comment on, including comparing two numbers and determining the status of an average; 3) a program that checks for duplicate values; 4) a program to find the smallest of three integers without using the min function; and 5) rewriting conditional expressions as if/else statements and vice versa. The document also notes there is an error in one of the programs that cannot be fixed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Islamic University of Gaza

Faculty of Engineering

Computer Engineering eparftment


d

Selections

Lab 4(1,2)

Produced By:

Ahmed Zakaria Albashiti 120153316

Introduced To:

Eng. Khalil Alassar

2020 – 2021
Lab4(1): -
1-

if temperature < 0:
print ("Below freezing")
elif temperature < 10:
print ("Very cold")
elif temperature < 20:
print (Chilly)
elif temperature < 30:
print("Warm")
elif temperature < 40:
print("Hot")
else:
print ("Too hot")
Islamic University of Gaza

Faculty of Engineering

Computer Engineering eparftment


d

2- Solve all labworks by your self and put them in the report , then put your own comments
on each one .

a)

b) Write a program that let the user enter two numbers, compare them to decide which one
is the largest and print it for the user . ( using conditional statement ) .
c) Write a program that request the user to enter an number represent as the average , then print
the status of average , as we did in the class :

There is an error in this program I can’t fix it.

There is an error in this program I can’t fix it.


Islamic University of Gaza

Faculty of Engineering

Computer Engineering eparftment


d

d)
3- Write a Python program that requests three integer values from the user. It then prints
one of two things: if any of the values entered are duplicates, it prints "DUPLICATES";
otherwise, it prints "ALL UNIQUE".
Islamic University of Gaza

Faculty of Engineering

Computer Engineering eparftment


d

4- Write a Python program that use an if statement to find the smallest of three given integers
without using the min function .
Lab4(2): -
Exercises: -
1. What is the output of the following code in (a) and (b) if number is 30, then if number is 35.
a)
if number % 2 == 0:

print (number, "is even.")

print (number, "is odd.")

b)
if number % 2 == 0:

print (number, "is even.")

else:

print (number, "is odd.")


Islamic University of Gaza

Faculty of Engineering

Computer Engineering eparftment


d

2. Rewrite the following if statement using a conditional expression:


if age >= 16:

ticketPrice = 20

else:

ticketPrice = 10

ticketPrice = 20 if age >= 16 else 10


3. Rewrite the following conditional expressions using if-else statements:
1. score = 3 * scale if x > 10 else 4 * scale

if x > 10:
score = 3 * scale
else:
score = 4 * scale
2. print (i if number % 3 == 0 else j)

if number % 3 == 0:
print(i)
else:
print(j)
4. Write a Python program that reads username and password from the user and
prints "successful login" if the username and password are correct, otherwise, it
prints "username or password is wrong".
Islamic University of Gaza

Faculty of Engineering

Computer Engineering eparftment


d

5. Write a Python program that uses an if statement to find the smallest of three given
integers. (The user should enter the three numbers).

You might also like