今天听斌哥讲了猜数游戏,觉得很有意思,分享给各位: 首先猜数游戏可以作为程序员平常忙碌的一个消遣,其次这样的程序简单易学让人能上手写
import random
ds = random.randint(1, 10)
print(f'内部人员提前得知:{ds}')
i = 0
while i < 3:
cds = int(input('请输入您猜的数:'))
if cds > 10 or cds < 1:
print('您的输入有误')
else:
if cds == ds:
print('恭喜您')
break
elif cds > ds:
print('猜大了')
else:
print('猜小了')
i += 1