【发布时间】:2015-08-11 16:40:42
【问题描述】:
我做了一个简单的猜数字程序,但是猜错了3次后我不知道如何再次尝试。有什么提示和技巧吗?
from random import randint
for i in range(1):
random_value = randint (1,10)
print "Guess the number"
tryes = 1
while tryes <= 3:
guess_1 = input('>')
if guess_1 > random_value:
print "The number is lower"
tryes = tryes + 1
elif guess_1 < random_value:
print "The number is higher"
tryes = tryes + 1
elif guess_1 == random_value:
print "You guessed right"
tryes = tryes + 3
else:
print "Invalid answer"
print "You won! Lets try that again shall we?"
【问题讨论】:
-
只需在末尾添加
os.system("python %s"%sys.argv[0])