This is all my homework for lessons 3.6 and 3.7
# 3.6 Pseudo + Hacks 1
statement1 = 46
statement2 = 43 + 3
if statement1 == statement2:
print("These two statements are equal to each other")
else:
print("These two statements are not equal to each other")
These two statements are equal to each other
# 3.6 Pseudo + Hacks 2
statement3 = "I like ducks"
statement4 = "I hate ducks"
yay = len(statement3)
more_yay = len(statement4)
if statement3 == statement4:
print("We are the same")
elif yay == more_yay:
print("We are the same length!")
else:
print("We are not that similar :(")
We are the same length!
# 3.6 Pseudo + Hacks 3
def number_asker(): # New function called number_aker
counter = 1 # sets a counter equal to 1
for i in range (1, 11): #Loop from 1-10
user_input = int(input(f"Enter {counter}: "))
while user_input != counter: # Keeps asking until number is correct
print(f"That's not {counter}. Try again")
user_input = int(input(f"Enter {counter}: "))
counter += 1 # Moves on to next number
print("You have successfully entered numbers 1-10! Congratulations, you know basic math!")
number_asker()
# 3.6 If statements Hack Number 1
weather = "rainy"
temperature = 56
great_day = (weather == "rainy") and (temperature <= 63)
if (great_day):
print("It will be a great day!")
It will be a great day!
# 3.6 If statements Hack Number 2
lala = 1000
lalala = 10 ** 3
if (lala == lalala):
print("They are equal!")
They are equal!
# 3.6 Else If statements Hack
def age_checky_thingy():
age = int(input("Please enter your age: "))
if 1 <= age <= 12: # Changing the lower bounds to 1 because what if they enter 1 and it ouputs adult?
print("You are a child.")
elif 13 <= age <= 17: # Checks if age is between 13 and 17
print("You are a teenager")
else: #Checks for above 18, assuming nobody enters 0
print("You are an adult")
age_checky_thingy()
# 3.7 Nested Conditionals 1
# Budget
budget = 1100
# Phone prices
iphone_15_price = 1204
iphone_12_price = 1099
iphone_10_price = 807
# Determine which iPhone you can buy
if budget >= iphone_15_price:
print("You can buy an iPhone 15!")
elif budget >= iphone_12_price:
print("You can buy an iPhone 12!")
elif budget >= iphone_10_price:
print("You can buy an iPhone 10!")
else:
print("You don't have enough money to buy an iPhone.")
You can buy an iPhone 12!
# 3.7 Nested Conditionals 2
# Ingredients
has_flour = True
has_sugar = True
has_eggs = True
has_milk = False
has_baking_powder = True
has_vanilla_extract = True
# Baking logic based on available ingredients
if has_flour and has_sugar:
print("You have the basic ingredients.")
if has_eggs:
print("You can make a basic cake batter.")
if has_milk:
print("Great! The cake will be moist.")
else:
print("You don't have milk, the cake might be a bit dry.")
if has_baking_powder:
print("Your cake will rise perfectly.")
else:
print("Without baking powder, the cake might not rise.")
if has_vanilla_extract:
print("The cake will have a nice vanilla flavor.")
else:
print("No vanilla extract, the flavor will be more basic.")
else:
print("You can't bake a cake without eggs.")
else:
print("You don't have enough ingredients to bake a cake.")
You have the basic ingredients.
You can make a basic cake batter.
You don't have milk, the cake might be a bit dry.
Your cake will rise perfectly.
The cake will have a nice vanilla flavor.
# Weather conditions
hot = False
mid = True
cold = True
foggy = False
rainy = True
thunderstormy = False
# Temperature logic based off of the conditions
if not hot and mid:
print("It's decent weather.")
if cold:
print("Cold weather is better weather")
if foggy:
print("Foggy weather is great weather")
else:
print("Unfortunately it's not foggy")
if rainy:
print("Rainy weather is wonderful weather! Be happy.")
else:
print("Unfortunately, it's not rainy")
if thunderstormy:
print("It's thunderstormy!! Thunderstorms are so fun.")
else:
print("Aww, it's not thunderstormy.")
else:
print("Aww it's just meh weather")
else:
print("Bad weather. Bad bad bad bad weather.")
It's decent weather.
Cold weather is better weather
Unfortunately it's not foggy
Rainy weather is wonderful weather! Be happy.
Aww, it's not thunderstormy.