Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed 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 number

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

Students also viewed these Databases questions

Question

What about leadership lessons from particularly good or bad bosses?

Answered: 1 week ago

Question

When would you use one approach, and when would you use another?

Answered: 1 week ago