Question
Python programming Write a program containing 2 functions and a main program that calls those functions to test them thoroughly. Step 1: Create a FUNCTION
Python programming
Write a program containing 2 functions and a main program that calls those functions to test them thoroughly.
Step 1: Create a FUNCTION called createMenu that creates a STRING which will produce the following output when printed by the main program. The function should accept TWO parameters: menuHeading (a string) and optionList (a list of strings). It should NOT PRINT ANYTHING it simply RETURNS a string.
HINT: initialize tmp to be an empty string, then use a loop that goes through the optionList one string at a time, concatenating a count, the string, and a newline character ( ) onto tmp , Return tmp when the loop is finished.
Step 2: Create another FUNCTION called getValidInput that accepts 3 parameters:
msg: a string that tells the user what they should be entering
start: a POSITIVE integer
end: a POSITIVE integer that is greater than start
This function should continue to ask the user to enter a number (using the msg parameter to describe what kind of number theyll be entering) until they type an integer that is in the range start to end, including both. If they enter a punctuation character, a letter, or something that isnt a number, print an error message asking them to try again. The function should RETURN a valid number.
Example main program to test these functions:
message = Enter a test score in the range 1-100 sc = getValidInput(message, 1, 100) print(Your test score: , sc, was in the proper range) prompt = Enter your guess 1 for heads, 2 for tails guess = getValidInput(prompt, 1,2) if guess == 1: print(You guessed heads) else: print(You guessed tails)
menuOptions = [ Add, Subtract,Quit] mainMenu = createMenu(Arithmetic Practice, menuOptions) print(mainMenu) optionList = [Savings Account, Checking Account, IRA Account, Exit] myMenu = createMenu(Bank Accounts, optionList) print(myMenu)
Employee Maintenance 1) Add a New Employee 2) Print Employee Roster 3) Delete an Employee 4) Sort List by Last Name 5) Exit. Please choose an item from the menu by typing its numberStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started