Fall 2024 - P1
Big Idea 3 | .1 | .2 | .3 | .4 | .5 | .6 | .7 | .8 | .10 |
3.6 Mastering Conditionals - Control Program Flow with IF, ELSE, and More
Student led teaching on Conditionals. Learn how conditionals control the flow of a program by executing specific blocks of code under certain conditions.
Solution
This is the solution to the 3.6 Homework Hack. This is just an example, your code may be slightly different and still be right.
# Function to compare two numbers
def compare_two_numbers(num1, num2):
# Check if the numbers are equal
if num1 == num2:
print("Both numbers are equal.")
# Find the larger number if they are different
elif num1 > num2:
print(f"The larger number is {num1}.")
else:
print(f"The larger number is {num2}.")
# Get user input
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
# Call the function to compare the two numbers
compare_two_numbers(num1, num2)