Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a python 3 program-containing 2 functions and a main program that calls th

ID: 3805590 • Letter: W

Question

Write a python 3 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 they’ll 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 isn’t 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)

Explanation / Answer

# -*- coding: utf-8 -*-
"""
Created on Tue Mar 28 01:37:37 2017

@author: nn186024
"""

def createMenu(str1,l1):
temp_values = " " + str1 + " "
for i in range(len(l1)):
temp_values = temp_values + " " + str(i+1) + " " + l1[i]

return temp_values

#def getValidInput()


if _name_ == '_main_':
'''Creating the list of values that will be passed as an argument to the createMenu function'''
menuoptions1 = ["Add","Subtract","Quit"]
'''calling the function createMenu with the arguments and assigning the return value to x'''
x = createMenu("Arithmetic Practise",menuoptions1)
print(x)
'''Creating the list of values that will be passed as an argument to the createMenu function'''
menuoptions2 = ["Savings Account", "Checking Account", "IRA Account", "Exit"]
'''calling the function createMenu with the arguments and assigning the return value to y'''
y = createMenu("Savings Account", menuoptions2)
print(y)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote