基本都给你加了注释,看不懂就再问吧import random
#删掉了很多重复代码
secret1 = random.randint(1,100)
secret2 = random.randint(1,9)#至少一次机会
#初始化ab
b = 0
a = 0
while a != secret1 and b < 10:
try:#输入错误检测
if b == 0:#判断是否是第一次猜,下面如果要针对第一次猜数字改变print的内容,可以用同样的方法
a = int(input("Guess a number and see what'll happen:"))
else:
a = int(input("Wrong number"))
if a == secret1:
print("I have to admit your rightness")
print("WTF handsome")
else:
if a > secret1:
print("Dont thou think it too bulky?")
print("Ohhhhhhhh")
else:
print("just like your penis")
print("Fuck it")
b = b+1#b放在这就只用一次就行了
except:#输入错误时反馈
print("请输入数字")
#进行下一次循环
continue
print("Time is up")
|