From 5c1017fcf6229b4549883bff08deb7a076d12fbc Mon Sep 17 00:00:00 2001 From: cheeks <134818917+leftovertoast@users.noreply.github.com> Date: Wed, 22 Jan 2025 11:37:37 -0500 Subject: [PATCH] Completed 5-2 More Conditional Tests --- Chapter_05/5-2_moreConditionalTests.py | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/Chapter_05/5-2_moreConditionalTests.py b/Chapter_05/5-2_moreConditionalTests.py index 7bda4a2..162724d 100644 --- a/Chapter_05/5-2_moreConditionalTests.py +++ b/Chapter_05/5-2_moreConditionalTests.py @@ -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)