Popcorn Hack #1
age = input("age: ") # variable that represents age
if int(age) >= 18: # ‘if’ and ‘print’ function that says “You are an adult” if your age is greater than or equal to 18.
print("Adult")
else:
print("Minor") # else statement tells user they are a minor
Popcorn Hack #2
is_raining = True
if is_raining:
print("Bring a umbrella")
else:
print("The weather is clear")
Popcorn Hack #3
import random
a = random.randint(0,100)
b = random.randint(0,100)
print(a, b)
if a > b:
print( str(a) + " > " + str(b) )
elif a < b:
print( str(a) + " < " + str(b) )
else:
print( str(a) + " = " + str(b) )
Homework Hack
Write a Python program that takes two numbers as input from the user. The program should:
Determine if the numbers are equal. If the numbers are different, print which number is larger.
# Get input from the user
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
# Compare the numbers
if num1 == num2:
print("The numbers are equal.")
else:
if num1 > num2:
print(f"The larger number is: {num1}")
else:
print(f"The larger number is: {num2}")