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,...
Input Format 4 1 2 3 4 Constraints there will be no more than 50 input...
Input Format 4 1 2 3 4 Constraints there will be no more than 50 input numbers. Output Format Odd: 2 Even: 2 Divisible by 7: 0 Average: 250 Sample Input 0 4 1 2 3 4 Sample Output 0 Odd: 2 Even: 2 Divisible by 7: 0 Average: 250 import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution {     public static void main(String[] args) throws IOException {         BufferedReader bufferedReader = new...
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...
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)...
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)
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....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT