[英]Python: Printing out list when I dont want to
我列出了函数列表,想随机选择一个琐事游戏,它会不断打印出列表中的函数。(我已经定义了函数)
def NBAquestions():x = 0问题6 =问题(“ NBA代表什么?”,“国家篮球直播”,“国家趣味直播”,“国家篮球联赛”,“无所事事但自由主义者”,3) .ask()== True:print(“您是正确的”)x + = 1否则:print(“ incorrect”)x-= 1
question7 = Question("What team won the championship last year (2016)?", "Golden State Warriors", "Miami Heat", "Minnesota Wild",
"Clevland Caviliers", 1)
if question7.ask() == True:
print("You are correct")
x += 1
else:
print("incorrect")
x -= 1
question8 = Question("What doesn't belong?", "Stephen Curry", "Kevin Durant", "Draymond Green",
"Mitch Marner", 4)
if question8.ask() == True:
print("You are correct")
x += 1
else:
print("incorrect")
x -= 1
question9 = Question("Is the Seattle Supersonics a current NBA team", "True", "False", "-",
"-", 2)
if question9.ask() == True:
print("You are correct")
x += 1
else:
print("incorrect")
x -= 1
question10 = Question("Micheal who?", "Jackson", "Johnson", "Jordan",
"Jarret", 3)
if question10.ask() == True:
print("You are correct")
x += 1
else:
print("incorrect")
x -= 1
print('Welcome to the Sports Trivia Game, you will compete head to head in a tivia matchup. One point will be awarded for getting 1 question right, but if you get 1 wrong you will lose a point')
a = input("please enter player 1's name: ")
b = input("please enter player 2's name: ")
questionList = ([NBAquestions(), MLBquestions(), NHLquestions(), NFLquestions()]
您必须使用随机数调用函数,并使用标志来完成游戏。
from random import randint # Generate random integers between 0 and 3
randomNum = (randint(0, 3)) # 0 1 2 3
while True:
if randomNum == 0:
NBAquestions()
elif randomNum == 1:
MLBquestions()
elif randomNum == 2:
NHLquestions()
elif randomNum == 3:
NFLquestions()
# Condition-flag indicate Game Over
# You have to declare your global variable inside your functions
# And when you have to end the game, set it True
global flag
if flag == True:
break
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.