From d91b49ddcb0ba3d832b1e12039eedd57b663d70b Mon Sep 17 00:00:00 2001 From: Eduard Prigoana Date: Sun, 23 Mar 2025 11:31:58 +0200 Subject: [PATCH] hw 20/3/25 11:31 AM --- py/MoreIfStatements/challenge1.py | 21 ++++++++++++++++++++ py/MoreIfStatements/challenge2.py | 32 +++++++++++++++++++++++++++++++ py/MoreIfStatements/challenge4.py | 12 ++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 py/MoreIfStatements/challenge1.py create mode 100644 py/MoreIfStatements/challenge2.py create mode 100644 py/MoreIfStatements/challenge4.py diff --git a/py/MoreIfStatements/challenge1.py b/py/MoreIfStatements/challenge1.py new file mode 100644 index 0000000..f4a6e5f --- /dev/null +++ b/py/MoreIfStatements/challenge1.py @@ -0,0 +1,21 @@ +# Ask the user to enter a number +num1 = int(input("Enter a number: ")) + +# Check if the first number is 5 +if num1 == 5: + print("You win") +else: + # If the first number is greater than 5 + if num1 > 5: + print("Too high, try again") + else: + print("Too low, try again") + + # Ask the user to enter another number + num2 = int(input("Enter another number: ")) + + # Check if the second number is 5 + if num2 == 5: + print("You win") + else: + print("You lose") diff --git a/py/MoreIfStatements/challenge2.py b/py/MoreIfStatements/challenge2.py new file mode 100644 index 0000000..41aaf1f --- /dev/null +++ b/py/MoreIfStatements/challenge2.py @@ -0,0 +1,32 @@ +# Start of the program + +# Prompt the user to enter the first number and convert it to an integer +num1 = int(input("Enter num1: ")) + +# Prompt the user to enter the second number and convert it to an integer +num2 = int(input("Enter num2: ")) + +# Calculate the sum of the two numbers +answer = num1 + num2 + +# Check if the sum is less than 20 +if answer < 20: + # If the sum is less than 20, print the sum + print("Output:", answer) + +# If the sum is exactly 20 +elif answer == 20: + # Print the message indicating the total is 20 + print("Output: The total is 20") + +# If the sum is greater than 20 +else: + # Multiply the sum by 3 as per the flowchart + answer *= 3 + # Print the modified answer + print("Output:", answer) + +# Print the goodbye message as the final step +print("Output: Goodbye") + +# End of the program diff --git a/py/MoreIfStatements/challenge4.py b/py/MoreIfStatements/challenge4.py new file mode 100644 index 0000000..e5099ed --- /dev/null +++ b/py/MoreIfStatements/challenge4.py @@ -0,0 +1,12 @@ +# Ask the user to select a color +color = input("Select a color (red, green, or blue): ").strip().lower() + +# Check the user's input and display the appropriate message +if color in ["red", "r"]: + print("You selected red.") +elif color in ["green", "g"]: + print("You selected green.") +elif color in ["blue", "b"]: + print("You selected blue.") +else: + print("Incorrect choice.")