import random
# 1。电脑出一个数字
# 策略 欧皇
xiao = 1
da = 100
caipan = random.randint(1,100)
ju = 0
for i in range(20):
ju = ju + 1
we = int(input("你猜是什么数字?"))
if caipan == we:
print("恭喜我们猜对")
break
elif caipan > we:
print("小了一点点")
elif caipan < we:
print("大了一点点")
dian= random.randint(xiao,da) # diang 电脑
if dian == caipan:
print("恭喜电脑猜对")
break
elif dian < caipan:
print("小了一点点")
xiao = dian + 1
elif dian > caipan:
print("大了一点点")
da = dian - 1
print("ni cai le ", ju,"ju")
name = '98k'
zidan = 50
# 我是98k
print("我是" + name + "我有" + str(zidan) + "子弹")
# 格式化字符串 %s 占位符 代替一个字符串 %d 占位符 代替一个数字
print("我是%s"%name)
print("我是%s,我有%d发子弹"%(name,zidan))
zhaowei -猜数字2.0
最新推荐文章于 2024-11-11 21:19:25 发布