I'm creating an infinite while loop that counts up or down between two user inputted numbers. When it reaches the end of the count, the user is asked "Would you like to start over? Enter Y to start over or N to exit:"
The full assignment is here -
The first prompt should be "Enter the starting number: "
The second prompt should be "Enter the ending number: "
The third prompt should be "Enter U to count up or D to count down: "
The program should then print each number from the starting number to the ending number (inclusive), each on a new line, going up or down depending on what the user entered
After printing the final number, the program should prompt the user "Would you like to start over? Enter Y to start over or N to exit: "
If the user enters Y, the program should start again with the first prompt. Otherwise, it should print "Goodbye!" and exit.
The prompts must be case insensitive, that is, the user should be able to enter Y or y, N or n, U or u, D or d
connection = True
while connection:
starting_number = int(input("Enter the starting number:\n"))
end_number = int(input("Enter the ending number:\n"))
the_count = input("Enter U to count up or D to count down:\n")
if the_count.upper() != "U":
for num in range(starting_number, end_number + 1):
if connection == end_number:
repeat_count = input("Would you like to start over? Enter Y to start over or N to exit:\n")
if repeat_count.upper() != "Y":
print(connection)
if repeat_count.upper() != "N":
print("Goodbye!")
break
if the_count.upper() != "D":
for num in range(end_number, starting_number - 1):
if connection == starting_number:
repeat_count = input("Would you like to start over? Enter Y to start over or N to exit:\n")
if repeat_count.upper() != "Y":
print(connection)
if repeat_count.upper() != "N":
print("Goodbye!")
break
else:
print("Goodbye!")
break
print()
After inputting the starting and end number, you are prompted to press U to count up or D to count down. If you type U, the prompt to enter first number appears again. If you type D, the function prints "Goodbye!".
Any help at all would be great! Thanks
Edit: Having looked at the answer here - Asking the user for input until they give a valid response I disagree that it is a duplicate. My function accepts user input and does not crash based on a mistake.