I'm trying to create this program
- Print a welcome message, and then prompt the user to select a difficulty by entering 1, 2 or 3.
- Use a loop to re-prompt the user until a valid response (1, 2 or 3) is entered.
Once a difficulty has been selected, print a message confirming the selected difficulty and set variables as follows:
1 was chosen:
lives = 3, max_num = 10 and questions = 52 chosen:
lives = 2, max_num = 25 and questions = 103 was chosen:
lives = 1, max_num = 50 and questions = 15
lives represents how many incorrect answers are permitted.
max_num represents the largest number enter code here used when generating a question.
questions represents the number of questions
The code below is what i have done so far
def input_valid_difficulty(prompt=''):
while True:
try:
n = int(input(prompt))
if n < 0 or n > 3:
raise ValueError
break
except ValueError:
print("Invalid choice! Enter 1,2 or 3.")
prompt = "Select a difficulty?: (0 to exit):"
return n
difficulty = input_valid_difficulty ("Select a difficulty?: (0 to exit):")
if difficulty == 0:
quit()
elif difficulty == 1:
print("Easy mode selected!")
elif difficulty == 2:
print("Medium mode selected!")
elif difficulty == 3:
print("Hard mode selected!")