IDNLearn.com provides a comprehensive solution for all your question and answer needs. Discover in-depth answers from knowledgeable professionals, providing you with the information you need.
Sagot :
Answer:
The program in Python is as follows:
print("Welcome to sorting program")
print("1. Title")
print("2. Rank")
print("3. Date")
print("4. Start")
print("5. Likes")
while(True):
choice = input("Enter a choice between 1 and 5 only: ")
if choice.isdigit() == True:
if(int(choice)>=1 and int(choice)<=5):
print("You entered valid choice", choice)
break;
else:
print("You have not entered a number between 1 and 5. Try again")
else:
print("You entered an invalid choice")
Explanation:
This prints the header
print("Welcome to sorting program")
The next 5 lines print the instructions
print("1. Title")
print("2. Rank")
print("3. Date")
print("4. Start")
print("5. Likes")
The loop is repeated until it is forcefully exited
while(True):
This prompts the user to enter a choice
choice = input("Enter a choice between 1 and 5 only: ")
This checks if the choice is a digit
if choice.isdigit() == True:
If yes, this checks if the choice is between 1 and 5 (inclusive)
if(int(choice)>=1 and int(choice)<=5):
If yes, this prints valid choice and the choice entered
print("You entered valid choice", choice)
The loop is exited
break;
If the choice is out of range
else:
This prints the error and tells the user to try again
print("You have not entered a number between 1 and 5. Try again")
If choice is not a digit
else:
This prints invalid choice
print("You entered an invalid choice")
We appreciate your contributions to this forum. Don't forget to check back for the latest answers. Keep asking, answering, and sharing useful information. Discover the answers you need at IDNLearn.com. Thank you for visiting, and we hope to see you again for more solutions.