ziheng -猜数字游戏

# 猜数字游戏
# 电脑随机出一个1-100的数字,我们猜,然后判断有没有猜中
# 电脑随机出一个1-100数字
import random
we = input("你想出什么数字?")  # 字符串
we = int(we)
# print(computer)
# 我们猜一个数字  input
for i in range(1000):
    # 策略:出一个中间数,慢慢缩小范围
    computer = random.randint(1,100) # 数字
    # 判断  15  16
    if we > computer:
        print("电脑猜小了")
    elif we < computer:
        print("电脑猜大了")
    elif we == computer:
        print("天选之脑")
        break
    print("电脑猜的是%d"%computer)

print("一共猜了%d局"%(i+1))
# 猜数字游戏
# 电脑随机出一个1-100的数字,我们猜,然后判断有没有猜中
# 电脑随机出一个1-100数字
import random
we = input("你想出什么数字?")  # 字符串
we = int(we)
# print(computer)
# 我们猜一个数字  input
for i in range(1000):
    # 策略:出一个中间数,慢慢缩小范围
    computer = random.randint(1,100) # 数字
    # 判断  15  16
    if we > computer:
        print("电脑猜小了")
    elif we < computer:
        print("电脑猜大了")
    elif we == computer:
        print("天选之脑")
        break
    print("电脑猜的是%d"%computer)

print("一共猜了%d局"%(i+1))
# continue 继续  跳出当前循环,进入下一次循环
# break   终止循环
for i in range(10):
    if i == 5:
        break
    print(i)


发布了352 篇原创文章 · 获赞 19 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/houlaos/article/details/104353223