Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to run multiple different functions based on user input

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading