Completed 5-2 More Conditional Tests

This commit is contained in:
cheeks 2025-01-22 11:37:37 -05:00
parent b73c970b85
commit 5c1017fcf6

View File

@ -45,3 +45,60 @@ print(lightSwitch == 'off')
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
'''
# String Equality Tests
string1 = 'Welcome'
string2 = 'Goodbye'
print("Are string1 & string2 equal?")
print(string1 == string2)
print("\nAre string1 & string2 different?")
print(string1 != string2)
# Using lower() method
string3 = 'Cheeks'
string4 = 'cheeks'
print("\nUsing lower are the names equal?")
print(string3.lower() == string4)
# Numerical tests <, >, <=, >=, ==
oneGig = 1024
twoGig = 2048
print("\nTwo gigs is bigger than one:")
print(oneGig < twoGig)
print("\nOne gig is bigger than two gigs:")
print(oneGig > twoGig)
print("\nTwo gigs is bigger or equal to one gigs equal the same amount:")
print(twoGig >= oneGig)
print("\nTwo gigs is less than or equal to one gig:")
print(twoGig <= oneGig)
print("\nTwo gigs is equal to one gig:")
print(twoGig == oneGig)
# Tests with AND & OR keywords
numOfPages = 77
print("\nThe number of pages is greater than 20 and also less than 100?")
print((numOfPages > 20) and (numOfPages < 100))
print("\nThe number of pages is either greater than 20 or less than 60?")
print((numOfPages > 20) or (numOfPages < 60))
# Test if item is in or not in list
myList = ['banana', 'pineapple', 'apple', 'pear', 'strawberry', 'peach']
print(f"\nmyList = {myList}")
print("\nLet's test if PINEAPPLE is in our list:")
print('pineapple' in myList)
print("\nLet's now test if BLUEBERRY is in our list:")
print('blueberry' in myList)