Question

In: Computer Science

print("1. Change Team: ") print("2. Choose Position") print("3. Quit") imp = input("Choose an option: ") if...

print("1. Change Team: ")
print("2. Choose Position")
print("3. Quit")
imp = input("Choose an option: ")
if imp == 1:
    chooseTeam()
elif imp == 2:
    choosePosition()
elif imp == 3:
    print("Goodbye")
else:
    print("Invalid option")
    imp2 = input("Choose an option (1-3): ")

This is my current code however I want it to loop back up to the top if an invalid option is input so it can reset the function

Solutions

Expert Solution

PYTHON CODE:

# Sample function for demonstration purpose only
def chooseTeam():
    print('Inside chooseTeam() function')
# Sample function for demonstration purpose only
def choosePosition():
    print('Inside choosePosition() function')
#############################################
#   Actual code goes here
#############################################
print("1. Change Team: ")
print("2. Choose Position")
print("3. Quit")
imp = int(input("Choose an option: "))
# Loop indefinitely till user enters 3 to exit
while True:
    if imp == 1:
        chooseTeam()
    elif imp == 2:
        choosePosition()
    elif imp == 3:
        print("Goodbye")
        break
    else:
        # If user entered invalid option print this msg
        print("Invalid option.")
        imp = int(input("Choose an option (1-3): "))
        # Skip the remaining part of the loop and go to top
        continue
    print("1. Change Team: ")
    print("2. Choose Position")
    print("3. Quit")
    imp = int(input("Choose an option: "))

SAMPLE OUTPUT:

FOR ANY HELP JUST DROP A COMMENT


Related Solutions

using python 3 1. Two-line input: print a prompt (e.g Enter your first name) and then...
using python 3 1. Two-line input: print a prompt (e.g Enter your first name) and then assign the input to a variable print ("Enter your first name")# the word prompt is the message the user should see firstName = input() print (firstName)
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
1. Motion is a process of (a) a change in time, (b) a change in position,...
1. Motion is a process of (a) a change in time, (b) a change in position, (c) a change in weight, (d) a change in mass. 2. Which of the following is a scalar quantity? (a) force, (b) speed, (c) velocity,               (d) acceleration. 3. The time rate of change of velocity is (a) speed, (b) acceleration, (c) friction,            (d) force. 4. In addition to a magnitude, a vector quantity has (a) time, (b) direction,                 (c) length, (d) an average value....
PYTHON 1- First, initialize the constant NUMS as 3: NUMS=3 2- Print the title of the...
PYTHON 1- First, initialize the constant NUMS as 3: NUMS=3 2- Print the title of the application. >---=== Python Temperature Analyzer ===---< 3- Using a for loop, prompt the user to enter the high and low values for each of NUMS days. The values entered must be between -40 and 40, and high must be greater than low. Print the following messages: > * Read the high value. > Enter the high value for day 1: < (or day 2,...
Find the net change of ?(?) = (? − 2)(? + 3) on the interval [-1,...
Find the net change of ?(?) = (? − 2)(? + 3) on the interval [-1, 1]. Find the net change of ?(?) = 6 cos ? on the interval [−? /2, ?/2]. Find the total area between ?(?) = ?3 − 2?2 and the x-axis on the interval [0, 5]. A ball is thrown upward from a height of 5 feet at an initial speed of 72 ft/sec. Acceleration resulting from gravity is -32 ft/sec2. Neglecting air resistance, find...
Use Python: Develop neurons and print truth table of the following 2-input logic gates: AND, OR,...
Use Python: Develop neurons and print truth table of the following 2-input logic gates: AND, OR, NAND, NOR, XOR, XNOR and 1-input NOT gate (Notice: use Markdown to explain how you developed a neuron, and to insert images showing the truth table of logic gates before coding)
Choose T/F for the following: (a) Gamma measures the option price change when the stock price...
Choose T/F for the following: (a) Gamma measures the option price change when the stock price increases. (b) Vega measures the change in the option price when there is an increase in volatility. (c) Theta measures the change in the option price when there is an increase in the time to maturity. (d) Rho measures the change in the option price when there is an increase in the interest rate. (e) For a call option, delta is not negative. (f)...
Question 1: 5pts Write a program to receive two integers as user input and then print:...
Question 1: 5pts Write a program to receive two integers as user input and then print: Sum Difference Product Average Maximum of the two Minimum of the two You may use the min and max functions declared in the math class. ********************************************************************************** Question 2: 10pts An online bank wants you to create a program that will show a prospective customer, how the deposit will grow. Your program should read the initial balance and the annual interest rate. Interest rate is...
Question 1: Write a program to receive two integers as user input and then print: Sum...
Question 1: Write a program to receive two integers as user input and then print: Sum Difference Product Average Maximum of the two Minimum of the two You may use the min and max functions declared in the math class. ********************************************************************************** Question 2: An online bank wants you to create a program that will show a prospective customer, how the deposit will grow. Your program should read the initial balance and the annual interest rate. Interest rate is compounded monthly....
How To Print Nice Padding Character in a String in C++? 1. User input the width...
How To Print Nice Padding Character in a String in C++? 1. User input the width = 14 2. User input the padding character = + Example output: ++Hello World++ Thanks in advance.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT