【发布时间】:2014-12-09 05:57:37
【问题描述】:
我在一个简单的硬币翻转程序中遇到了这个奇怪的问题,当我运行此代码时,它并没有给我某种错误,而是发生了某种崩溃。我输入是或否的答案,然后按回车,但它什么也没做。然后我再次按回车,它完全关闭了。
import time
import random
constant = 1
FirstRun = True
def Intro():
raw_input("Hello and welcome to the coin flip game. Do you wish to flip a coin? (yes or no): ")
def CoinToss():
print "You flip the coin"
time.sleep(1)
print "and the result is..."
time.sleep(1)
result = random.randint(1,2)
if result == 1:
print "heads"
if result == 2:
print "tails"
while constant == 1:
if FirstRun == True:
Intro()
FirstRun = False
else:
answer = raw_input()
if answer == "yes":
CoinToss()
raw_input("Do you want to flip again? (yes or no): ")
else:
exit()
【问题讨论】: