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)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值