# 电脑出一个随机数
import random
smallest_num = 1
biggest_num = 1000000
number = input("请出一个数字(%d-%d):"%(smallest_num,biggest_num))
number=int(number)
for i in range(1000):
# integer 整数 int
# print(number)
# 我们猜一个数字
# 策略:平均数
# we = random.randint(1, 100) # string 字符串 str
we = (biggest_num+smallest_num)/2
we=int(we)
print(we)
if we == number:
print("欧洲人实锤")
break
elif we < number:
print("猜小了")
smallest_num = we
elif we > number:
print("猜大了")
biggest_num = we
print("你一共猜了%d次" %(i+1))
name = "老八"
age = 22
# hi= "哈喽"
# 哈喽蛋黄派,你今年22岁了
print("哈喽"+name+"你今年"+str(age)+"岁了")
# 格式化字符串 %s 占位符 替代一个字符串
print("哈喽 %s"%name)
# %d 占位符 替代一个数字
print("哈喽 %s,你今年%d岁了"%(name,age))
aden-猜数字升级版
最新推荐文章于 2021-07-26 17:36:02 发布