Question

in Python: Write a program that allows the user to enter a number between 1-5 and...

in Python: Write a program that allows the user to enter a number between 1-5 and returns an animal fact based on what the user entered. The program should 1. Continue to run until the user enters “quit” to terminate the program, and 2. Validate the user’s input (the only acceptable input is 1, 2, 3, 4, 5 or “quit”). You can use the following animal facts:

  1. An octopus is a highly intelligent invertebrate and a master of disguise.
  2. Elephants have the largest brain of any land animal and three times as many neurons as humans.
  3. African Grey Parrots are capable of abstract logical reasoning.
  4. Whales and dolphins have specialized neurons associated with advance abilities such as recognizing, remembering, reasoning, communicating, perceiving, adapting to change, and understanding.
  5. Crows and other corvids have incredible memories and can remember human faces.

All code must be contained in a function (except comments and import statements). You will have to implement the following four functions in your program:

  • printWelcome – a helper function that prints welcome message and instructions to the user.
  • inputValidation – a helper function that takes user input as an argument, returns a Boolean value “true” if user input is valid, and returns a Boolean value “false” otherwise.
  • printFact – a helper function that takes the valid user input as an argument, and prints an animal fact based on what the user entered.
  • main – this function allows the user to continue until the user enters “quit”, uses the appropriate helper functions, and print a thank you message when the user enters “quit” as shown in the sample run below.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#printWelcome – a helper function that prints welcome message and instructions to the user.
def printWelcome():
print("Welcome to animal facts programme. \nPlease enter a number between 1-5. enter quit to terminate the programme\n--------------------------------------------\n")
#inputValidation – a helper function that takes user input as an argument, returns a Boolean value “true” if user input is valid, and returns a Boolean value “false” otherwise.
def inputValidation(num):
#Validate the user’s input (the only acceptable input is 1, 2, 3, 4, 5 or “quit”)
if(num=='1' or num=='2' or num=='3' or num=='4' or num=='5' or num=='quit'):
return True
else:
return False
#printFact – a helper function that takes the valid user input as an argument, and prints an animal fact based on what the user entered.
def printFact (argument):
   switcher = {
       '1': "An octopus is a highly intelligent invertebrate and a master of disguise.",
       '2': "Elephants have the largest brain of any land animal and three times as many neurons as humans.",
       '3': "African Grey Parrots are capable of abstract logical reasoning.",
'4': "Whales and dolphins have specialized neurons associated with advance abilities such as recognizing, remembering, reasoning,",
       '5': "communicating, perceiving, adapting to change, and understanding.",
   }
   return switcher.get(argument, "nothing")

#main – this function allows the user to continue until the user enters “quit”, uses the appropriate helper functions, and print a thank you message when the user enters “quit” as shown in the sample run below.
if __name__ == "__main__":
printWelcome()
while(True):
argument=input("Enter a number :")
# Continue to run until the user enters “quit” to terminate the program
if(argument=='quit'):
print("Thank You")
break
if(inputValidation(argument)):
print (printFact(argument))
else:
print("Enter valid input")

Enter a number: Enter valid input Enter a number :5 communicating, perceiving, adapting to change, and understanding Enter a

def printWelcome ) print Welcome to animal facts programme. \nPlease enter a number between 1-5. enter quit to terminate the

Add a comment
Know the answer?
Add Answer to:
in Python: Write a program that allows the user to enter a number between 1-5 and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In python 3, 1. Write a program that takes a number of credit hours and returns...

    In python 3, 1. Write a program that takes a number of credit hours and returns a classification as follows: 29 credits or less: freshman; 30-59 credits: sophomore; 60-89 credits: junior; 90+ credits: senior. 2. Use a loop to valid input such that users can only enter positive numbers. 3. Use a loop to allow the user to keep entering credit hours and receiving classifications until they quit. All code must be in a function. I suggest the following structure:...

  • Write a PYTHON program that allows the user to navigate the lines of text in a...

    Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the...

  • In C++ 1. Write a program that allows a user to enter 10 integer values from...

    In C++ 1. Write a program that allows a user to enter 10 integer values from the keyboard. The values should be stored in an array. 2. The program should then ask the user for a number to search for in the array: The program should use a binary search to determine if the number exists in a list of values that are stored in an array (from Step #1). If the user enters a number that is in the...

  • Please help me with this Python program. Write a program that takes the plastic identification number...

    Please help me with this Python program. Write a program that takes the plastic identification number from the user and returns information. The program should allow the user to continue using the program until they quit. It should also validate the input and only accept the integers 1-7 as input. All code should be in a function. I suggest the following function structure: printWelcome - prints program information validateUserinput1 to7 - takes user input, validates, and returns valid input main...

  • Write a Java program which allows the user to perform simple tasks on a calculator. A...

    Write a Java program which allows the user to perform simple tasks on a calculator. A series of methods allows the user to select an operation to perform and then enter operands. The first method displays a menu, giving the user the choice of typing in any one of the following: +, -, *, /, or % representing the usual arithmetic operators (Each operation should be done on numbers negative(-) to positive(+), positive(+) to negative(-), negative(-) to negative(-), and positive(+)...

  • Write a program which: - prompts the user for 2 numerical inputs - stores their two...

    Write a program which: - prompts the user for 2 numerical inputs - stores their two inputs in variables as floats - Use a while in loop to ask a user for a valid operation: (if the user's input operation isn't one of those listed above, instead print a message telling them so, and continue asking for the valid operation) - prompts the user for an arithmetic operation ( + - * / %) - stores the user's input as...

  • In Python, write a program that asks the user for a positive integer number. If the...

    In Python, write a program that asks the user for a positive integer number. If the user enters anything else, the program would ask the user to re-enter a number or enter -1 to quit. If it is a positive number, the program then prints out a multiplication table that goes up to that number. For example, if the user enters 10, the output would look something like this. https://www.vectorstock.com/royalty-free-vector/multiplication-table-on-white-background-vector-2721686

  • This is Python The program should accept input from the user as either 7-digit phone number...

    This is Python The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12. The program should not crash if the user enters invalid...

  • In Python Calculator Write a program that allows the user to enter two numbers and then...

    In Python Calculator Write a program that allows the user to enter two numbers and then adds, subtracts, divides or multiplies them when the user clicks on the appropriate button. Make sure you have a Quit button. Modification and requirements”: _____Window title should be  your name Calculate self.main_window.title("?????") _____Labels - change the attributes of the color, font, size and bold the answerExample self.label = tkinter.Label(self.main_window, \ text='?????????!', font=(" should Arial", 12, "bold"), fg="blue", bg="pink")Tip: choose a color from the...

  • Write a contacts database program that presents the user with a menu that allows the user...

    Write a contacts database program that presents the user with a menu that allows the user to select between the following options: (In Java) Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT