Home > OS >  The result prints the amount of items in a list [closed]
The result prints the amount of items in a list [closed]

Time:09-28

#list
gamesAvailable = ["Minecraft", "League of Legends", "Valorant", "Wild Rift", "Mobile Legends", "Call of Duty", "Pokémon", "Esports King", "Sims", "Mir4"]
print(gamesAvailable, end = ", ")

#input game
gameSelection = input("\nSelect your Game: ")

#for loop
for games in gamesAvailable:
    if gameSelection == "Minecraft":
        print("You have selected", gamesAvailable [0])
    elif gameSelection == "League of Legends":
        print("You have selected", gamesAvailable [1])

is there a way where the result can only print one time?

CodePudding user response:

for x in range(len(gamesAvailable))
    print(gamesAvailable[x])

or

print(*gamesAvailable)

or with a comma sep

print(*gamesAvailable, sep = ', ')

CodePudding user response:

You do not need the for loop -

gamesAvailable = ["Minecraft", "League of Legends", "Valorant", "Wild Rift", "Mobile Legends", "Call of Duty", "Pokémon", "Esports King", "Sims", "Mir4"]
print(gamesAvailable, end = ", ")

#input game
gameSelection = input("\nSelect your Game: ")

if gameSelection == "Minecraft":
   print("You have selected", gamesAvailable [0])
elif gameSelection == "League of Legends":
   print("You have selected", gamesAvailable [1])
  • Related