【发布时间】:2018-03-27 19:03:10
【问题描述】:
我正在用 python 创建一个程序,我需要向用户询问团队名称和团队成员。我需要将团队名称放在列表中,并将团队成员嵌入团队名称中。有什么帮助吗?
# Creating Teams
print("Welcome to the program")
print("======================================================")
Teams = []
# Looping to find out the four different team names and players.
for x in range(0, 4) :
# Asking for the Team name and the team players names
TeamName = input("What is the name of the team?")
Player1 = input("What is the first name of the player in your team?")
Player2 = input("What is the second name of the player in your team?")
Player3 = input("What is the third name of the player in your team?")
Player4 = input("What is the last name of the player in your team?")
Teams.extend([TeamName, Player1, Player2, Player3, Player4])
TeamPlayers = int(input("What Team do you want to see? (0-4)"))
print([Teams, Player1, Player2, Player3, Player4])
【问题讨论】:
-
问题/疑问是什么?请花时间阅读How to Ask 以及该页面上的其他链接。
-
对什么有任何帮助吗?您发布的代码似乎解决了您提出的问题。
-
这里可能适合使用字典。
-
也许使用
Teams.append而不是Teams.extend,因为extend会给你一个包含所有团队混合在一起的列表,而append会给你一个包含每个团队单独列表的列表。 -
寻求帮助不一定是在 SO 的上下文中提出问题。你有什么问题?这只是让别人为你写代码的一种方式吗?