0% found this document useful (0 votes)
16 views3 pages

Lesson For Programming 3

The document discusses Python conditional operators like >, <, >=, <=, ==, != and provides examples of using conditional statements with if, else, and elif to check conditions and execute code based on different conditions being true or false. Multiple examples are given to check grades, usernames and passwords, and different fruit types.

Uploaded by

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

Lesson For Programming 3

The document discusses Python conditional operators like >, <, >=, <=, ==, != and provides examples of using conditional statements with if, else, and elif to check conditions and execute code based on different conditions being true or false. Multiple examples are given to check grades, usernames and passwords, and different fruit types.

Uploaded by

mmfarrelly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#conditional operator

# >, <, >=, <=, ==, !=

num = input ("Enter a number: ")


if int(num) > 10:
print ("Yes!its more than 10")
else:
print ("No! its less than 10")

c:\python_files>python condition1.py
Enter a number: 5
No! its less than 10

c:\python_files>python condition1.py
Enter a number: 20
Yes!its more than 10

=======================

m = input ("Math Grade: ")


s = input ("Math Science: ")
e = input ("Math English: ")

ave = (float(m) + float(s) + float (e))/3

if ave >= 75:


print(str(ave))
print("You passed the semester!")
else:
print (str(ave))
print ("Sorry! You failed.")

c:\python_files>python condition2.py
Math Grade: 70
Math Science: 71
Math English: 72
71.0
Sorry! You failed.

c:\python_files>python condition2.py
Math Grade: 85
Math Science: 89
Math English: 88
87.33333333333333
You passed the semester!
==========================

u = input ("Enter username: ")


p = input ("Enter password: ")

if u == "admin":

if p == "1234":
print("Welcome admin")
else:
print("Error!")

else:
print("Error!")
c:\python_files>python condition3.py
Enter username: admin
Enter password: 4566
Error!

c:\python_files>python condition3.py
Enter username: monna
Enter password: 1234
Error!

c:\python_files>python condition3.py
Enter username: admin
Enter password: 1234
Welcome admin
=========================
YOU CAN USE "AND" MANY TIMES.

c:\python_files>python condition3.py
Enter username: admin
Enter password: 4566
Error!

c:\python_files>python condition3.py
Enter username: monna
Enter password: 1234
Error!

c:\python_files>python condition3.py
Enter username: admin
Enter password: 1234
Welcome admin

c:\python_files>python condition4.py
Enter username: admin
Enter password: 456
Account Error!

c:\python_files>python condition4.py
Enter username: monna
Enter password: 1234
Account Error!

c:\python_files>python condition4.py
Enter username: admin
Enter password: 1234
Welcome Admin
==============
elif - means you want to check multiple

fruit = input ("Type a fruit: ")

if fruit == "apple":
print("Red Apple!")

elif fruit == "guava":


print("Green Guava!")

elif fruit == "banana":


print("Yellow Banana!")

else:
print("Not Available!")

c:\python_files>python condition5.py
Type a fruit: guava
Not Available!

c:\python_files>python condition5.py
Type a fruit: banana
Yellow Banana!

c:\python_files>python condition5.py
Type a fruit: apple
Red Apple!

c:\python_files>python condition5.py
Type a fruit: guava
Green Guava!
=====================

You might also like