-4

I'm making a ranking system, and I was wondering if you could use an input to select an item from a list. And if the input matches any item in the list, you could assign points to it.

Here's what I got so far:

teams = list()
scores = list()

#adding a team
if loop=="1":
    team_name = input("Enter a team name: ")
    print ("This team is succesfully added!")
    teams.append(team_name)

#selecting the team by user input
elif loop=="4":
   test = input("Enter a team name: ")
   if test is any in list(teams):
       score_team = int(input("How many points does this team get? "))
       scores.append(score_team)
   else:
       print("Sorry, thats not a valid team name!")   

I always get the output:

Sorry, thats not a valid team name!.

What am I doing wrong?

Lafexlos
  • 7,618
  • 5
  • 38
  • 53
L. Kappa
  • 25
  • 2
  • 6

1 Answers1

-1

Just check if the list contain the team entered by the user using 'in' keyword. so it should work

teams = list()
scores = list()

#adding a team
if loop=="1":
    team_name = input("Enter a team name: ")
    print ("This team is succesfully added!")
    teams.append(team_name)

#selecting the team by user input
elif loop=="4":
   test = input("Enter a team name: ")
   if test in list(teams):
       score_team = int(input("How many points does this team get? "))
       scores.append(score_team)
   else:
       print("Sorry, thats not a valid team name!")   
hrishi
  • 443
  • 2
  • 12