在输出中打印用户的输入?

时间:2017-12-05 17:08:17

标签: python list input output

我有一个大约5个项目的列表,它是关于一个足球甲骨文,用户在两个团队中输入,然后程序从提到的列表中随机选择一个答案。 所以我想在回答问题时考虑用户的输入,因为此刻它只是一般句子。 例如,如果用户输入"曼联"作为主队和" FC Basel"作为访客团队,我希望使用名称代替主页来回答该计划。 但我怎么可能这样做?

1 个答案:

答案 0 :(得分:-1)

import random
teams = [] #list of the teams that will be in "competition"
hometeam = input("Who is the home team? ").title()
teams.append(hometeam) #adds this team to the list
awayteam = input("Who is the away team? ").title()
teams.append(awayteam) #adds this team to the list
print(random.choice(teams)) #chooses random item in the list and prints it