代码思想: 随机给定一个1-100的数,让别人猜,猜对了返回对应猜测了多少次
import random
i
=1
print("数字在1-100之间")
S
= random
.randint
(1, 100)
while 1:
n
=eval(input("请输入数字:"))
if n
>S
:
print("遗憾,太大了")
i
=i
+1
elif n
<S
:
print("遗憾,太小了")
i
=i
+1
else:
print("恭喜,经历了{}次,你猜中了".format(i
))
break
程序效果图:
转载请注明原文地址: https://lol.8miu.com/read-37366.html