Trying to run multiple different functions based on user input

Question:

tnames = []
inames = []
    def teamEnter():
        for x in range (4):
            tnames.append(input("Please enter a team name:"))
        print(tnames)
        tevent1()
        tevent2()
    #This loops 4 times and asks you to enter 4 team names
        
    def individualEnter():
        for x in range (20):
            inames.append(input("Please enter an individuals name:"))
        print(inames)
        ievent1()
    #This loops 20 times and asks you to enter 20 individual names
        
    
    def intro():
        inp = input("Would you like to hold a tournament for teams or individuals: ")
        # Asks the user to enter as a team or individual
        print (' ')
        TeamOrIndividual = str(inp)
        if inp == "Individuals":
            individualEnter()
        elif inp =="Teams":
            teamEnter()
    #This is the initial home page where you choose between teams or individuals
    intro()
    
    def tevent1():
        print("This is the relay race event")

    def tevent2():
        print("This is the football event")

        
    def ievent1():
        print("This is the tug of war event")

    def ievent2():
        print("This is the dodgeball event")

I want to be able to run the tevent1 and tevent2 when the user inputs ‘Teams’ when the code is run and the ievent1 and ievent2 when the user inputs ‘Individuals’ when the code is run.

How do i do this?

I tried IF statements to see if that worked by it didnt

Asked By: Birds

||

Answers:

Is this what you are trying to do?

tnames = []
inames = []

def teamEnter():
    for _ in range(4):
        tnames.append(input("Please enter a team name:"))
    print(tnames)
    tevent1()
    tevent2()
#This loops 4 times and asks you to enter 4 team names
  
def individualEnter():
    for _ in range(20):
        inames.append(input("Please enter an individuals name:"))
    print(inames)
    ievent1()
    ievent2()
#This loops 20 times and asks you to enter 20 individual names

def tevent1():
    print("This is the relay race event")

def tevent2():
    print("This is the football event")

def ievent1():
    print("This is the tug of war event")

def ievent2():
    print("This is the dodgeball event")


inp = input("Would you like to hold a tournament for teams or individuals: ").lower()
# Asks the user to enter as a team or individual
print()
if inp == "individuals":
    individualEnter()
elif inp =="teams":
    teamEnter()
Answered By: nonlinear
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.