Question: I have the following in my python: # Define the correct answer correct_answer = 4 # Keep asking the user for the answer until they
I have the following in my python: # Define the correct answer correct_answer = 4 # Keep asking the user for the answer until they answer correctly while True: # Ask the user for the answer user_answer = int(input("What is 2 + 2? ")) # Check if the user's answer is correct if user_answer == correct_answer: # If the answer is correct, congratulate them and end the program print("Correct. Congratulations!") break else: # If the answer is incorrect, re-prompt them until they answer correctly print("Wrong, try again.")
I need to answer this question based on what i did above: Exercise #2.9: (3 points) Modify Exercise #8 so that your program prompts the user for a random addition problem instead of always asking them to answer "What is 2+2?". Pseudo code: Generate 2 random numbers, num1, num2. Enter while loop Prompt the user "what is num1 + num2" equal? check the answer, if the input value equals the num1 + num2 then print "Correct!" Else, print "Incorrect" and try again. End loop.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
