zoukankan      html  css  js  c++  java
  • Python猜数小游戏

    1. 使用random变量随机生成一个1到100之间的数

    2. 采集用户所输入的数字,如果输入的不符合要求会让用户重新输入。

    3. 输入符合要求,游戏开始。如果数字大于随机数,输出数字太大;如果小于随机数,输出数字太小

    4. 猜对,输出数字正确,猜的次数;并询问是否继续游戏

    5. 用户回答y(yes)表示继续玩

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    import random
    rnum=random.randint(1,100)
    count=0
     
    while True:
        num=input('please enter a number(1,100):  ').strip()
        if num.isdigit():
            num=int(num)
            count += 1
            if num == rnum:
                print('yes,{} is right;you guess {} times'.format(num,count))
                ask=input('would you like play again(y/n):  ').strip().lower()
                if ask == 'y':
                    continue
                else:
                    break
                break
            elif num > rnum:
                print('you number is too lager!')
                continue
            else:
                print('you number is too small!')
                continue
        else:
            print('you number is invalid,please enter again')
            continue

     

  • 相关阅读:
    Win10 WSL Ubuntu18.04 编译安装MySQL5.7
    PHP7 深入理解
    php session 测试
    nginx 匹配路由分发php和golang
    composer 库无法提交git
    Win10 1803安装Ubuntu1804子系统
    dhtmlxTreeGrid使用
    win7 64位系统下安装PL/SQL连接Oracle服务器的解决方法
    转载--eclipse快捷键
    JUnit4学习笔记2-Eclipse中使用JUint4进行单元测试
  • 原文地址:https://www.cnblogs.com/aiaitie/p/9333995.html
Copyright © 2011-2022 走看看