新人课后作业 猜字游戏
"""猜字游戏"""import random #导入random模块
counts = 3
answer = random.randint(1, 20)#randint随机answer为随机数
while counts > 0: #循环次数
temp = input ('输入我想的数')
member = int(temp)
if member == answer:
print("哈哈真确哦")
break
else:
if member > answer:
print("大了")
else:
print("小了")
counts = counts - 1 #错一次少一次机会
cishu = int (counts)
print(cishu,"次机会") #打印剩余次数
print("游戏结束正确数为",answer)
counts 一开始赋值就是 int 吧?倒数第三句 cishu = int (counts) 应该不用转类型吧? 阿铠 发表于 2020-9-11 15:59
counts 一开始赋值就是 int 吧?倒数第三句 cishu = int (counts) 应该不用转类型吧?
同意,直接Print(counts,'次机会')也没问题啊
页:
[1]