#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])
是否有一种方法,结果只能打印一次?
不需要for循环-
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])
for x in range(len(gamesAvailable))
print(gamesAvailable[x])
或
print(*gamesAvailable)
或加逗号sep
print(*gamesAvailable, sep = ', ')