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

Python Practical Worksheet 3

The document provides an overview of logical conditions in Python, including comparison operators and their usage in if statements and loops. It includes examples of checking if numbers are greater, equal, even, odd, positive, negative, and implementing simple calculators. Additionally, it discusses grading based on student scores using conditional statements.

Uploaded by

Nazia A Abdullah
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)
3 views

Python Practical Worksheet 3

The document provides an overview of logical conditions in Python, including comparison operators and their usage in if statements and loops. It includes examples of checking if numbers are greater, equal, even, odd, positive, negative, and implementing simple calculators. Additionally, it discusses grading based on student scores using conditional statements.

Uploaded by

Nazia A Abdullah
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/ 2

if x > 20:

print("and also above 20!")


else:
Python supports the usual logical conditions print("but not above 20.")
from mathematics:
 Equals: a == b #6 takes input a number and checks if its greater
 Not Equals: a != b than 10 and greater than 20 and also if its not
 Less than: a < b above 20
 Less than or equal to: a <= b x= int(input(“Enter any number”))
 Greater than: a > b if x > 10:
 Greater than or equal to: a >= b print("Above ten,")
These conditions can be used in several ways, elif x > 20:
most commonly in "if statements" and loops. An print("and also above 20!")
"if statement" is written by using the if keyword. else:
print("but not above 20.")
# 1 compare two values and checks which value
is greater. # 7 Check if a number is even or odd
a =10
a = 33 if (a % 2) == 0 :
b = 200 print ("even number")
if b > a: else :
print("b is greater than a") print ("Odd number")

# 2 checks if b is grater than a else prints they #8 checks if a number is positive or negative or
are equal zero
a = 33 number = -5
b = 33 if number > 0:
if b > a: print('Positive number')
print("b is greater than a") elif number < 0:
else : print('Negative number')
print("a and b are equal") else:
print('Zero')
# 3 checks if the values are greater or equal
a = 200 #9 A simple calculator to add and subtract which
b = 33 asks the user if you want to add ,if user types Y
if b > a: it will add the numbers else it will subtract them.
print("b is greater than a")
elif a == b: number1 = 70
print("a and b are equal") number2= 80
else: answer = input(“Do you want to add?(Y/N))
print("a is greater than b") if answer == “Y” :
result = number1 + number2
# 4 checks if both a is greater than b and c is else
greater than a result = number1 - number2
a = 200 print(result)
b = 33
c = 500
if a > b and c > a: #10 make simple calculator to multiply or divide
print("Both conditions are True") using the same logic as above.

#5 check if the value of x is greater than 10 and


outputs the statement
x = 41
if x > 10:
print("Above ten,")
#11 Use else if statements to check if the student
has achieve which grade.

1. If a student scores above 90, assign grade A

2. If a student scores above 75, assign

grade B

3. If a student scores above 65, assign

grade C

You might also like