在其他论坛的帮助下,我制作了一份问卷或简短而简单的数学测验。我有问题作为函数,它们的答案在其中,例如:
def q1():
print("What is 6 divided by 2?")
answer = str(input())
if answer == "3":
print("You have {} lives left".format(lives)) # displays the current lives (does not lose a life)
print("CORRECT!")
else:
lives -= 1 # loses a life
print("You have {} lives left".format(lives)) # displays the current lives (loses a life)
print("WRONG!")
q1()
我有四个这样的问题,它们都在一个函数中:
def questions():
def q1():
print("What is 6 divided by 2?")
answer = str(input())
if answer == "3":
print("You have {} lives left".format(lives)) # displays the current lives (does not lose a life)
print("CORRECT!")
else:
lives -= 1 # loses a life
print("You have {} lives left".format(lives)) # displays the current lives (loses a life)
print("WRONG!")
q1()
time.sleep(2)
print()
def q2():
print("What is 6 multiplied by 2?")
answer = str(input())
if answer == "12":
print("You have {} lives left".format(lives)) # displays the current lives (does not lose a life)
print("CORRECT!")
else:
lives -= 1 # loses a life
print("You have {} lives left".format(lives)) # displays the current lives (loses a life)
print("WRONG!")
q2()
time.sleep(2)
print()
def q3():
print("What is 5 multiplied by 5?")
answer = str(input())
if answer == "12":
print("You have {} lives left".format(lives)) # displays the current lives (does not lose a life)
print("CORRECT!")
else:
lives -= 1 # loses a life
print("You have {} lives left".format(lives)) # displays the current lives (loses a life)
print("WRONG!")
q3()
time.sleep(2)
print()
def q4():
print("What is 20 divided by 2?")
answer = str(input())
if answer == "12":
print("You have {} lives left".format(lives)) # displays the current lives (does not lose a life)
print("CORRECT!")
else:
lives -= 1 # loses a life
print("You have {} lives left".format(lives)) # displays the current lives (loses a life)
print("WRONG!")
q4()
questions()
我的完整代码^上面^ 当我打开python交互窗口时,屏幕上没有显示或打印任何内容。