• Python demo working


    一、游戏1、2、3

    print("-------------- Guess Number Game---------------------")
    num=input("Guess Number")
    guess = int(num)
    print(guess)
    if guess == 6:
        print("true")
    else:
        if guess >6:
            print("大了")
        else:
            print("小了")
    print("Game Over!Thanks。")
    print("-------------- Guess Number Game---------------------")
    num=input("Guess Number")
    guess = int(num)
    if guess ==6:
        print("true")
    else:
        while guess !=6:
            if guess == 6:
                print("true")
            else:
                if guess >6:
                    print("大了")
                else:
                    print("小了")
            number= input("false,Guess Again")
            guess = int(number)
            if guess ==6:
                print("true")
    print("Game Over!Thanks。")
    import random
    secret =random.randint(1,10)
    print("-------------- Guess Number Game---------------------")
    num=input("Guess Number")
    guess = int(num)
    if guess == secret:
        print("true")
    else:
        while guess !=secret:
            if guess == secret:
                print("true")
            else:
                if guess >secret:
                    print("大了")
                else:
                    print("小了")
            number= input("false,Guess Again")
            guess = int(number)
            if guess ==secret:
                print("true")
    print("Game Over!Thanks。")

    二、打印乘法表、冒泡排序

    # 打印乘法表
    for x in range(1,10):
        for y in range(1,10):
            if y <=x:
                print(("%d * %d = %d"%(y,x,x*y)+"	"),end="")
        print()
    
    # 1 * 1 = 1
    # 1 * 2 = 2    2 * 2 = 4
    # 1 * 3 = 3    2 * 3 = 6    3 * 3 = 9
    # 1 * 4 = 4    2 * 4 = 8    3 * 4 = 12    4 * 4 = 16
    # 1 * 5 = 5    2 * 5 = 10    3 * 5 = 15    4 * 5 = 20    5 * 5 = 25
    # 1 * 6 = 6    2 * 6 = 12    3 * 6 = 18    4 * 6 = 24    5 * 6 = 30    6 * 6 = 36
    # 1 * 7 = 7    2 * 7 = 14    3 * 7 = 21    4 * 7 = 28    5 * 7 = 35    6 * 7 = 42    7 * 7 = 49
    # 1 * 8 = 8    2 * 8 = 16    3 * 8 = 24    4 * 8 = 32    5 * 8 = 40    6 * 8 = 48    7 * 8 = 56    8 * 8 = 64
    # 1 * 9 = 9    2 * 9 = 18    3 * 9 = 27    4 * 9 = 36    5 * 9 = 45    6 * 9 = 54    7 * 9 = 63    8 * 9 = 72    9 * 9 = 81
    
    #冒泡排序
    import random
    lis=[x for x in range(10)]
    random.shuffle(lis)
    print(lis) # [2, 5, 0, 6, 4, 3, 7, 8, 1, 9]
    
    for x in range(9):
        for y in range(9): # for y in range(len(lis)-1-x): python的冒泡排序
    if lis[y] >lis[y+1]: lis[y],lis[y+1]=lis[y+1],lis[y] print(lis) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

    三、点将台游戏

    点将台.py

    import 点将小助手 as dj
    while True:
        dj.show_menu()
        user_action = input('请输入你想要的操作')
        if user_action in ['1','2','3','0']:
            if user_action =='1':
                dj.add_stu()
            elif user_action =='2':
                dj.show_all()
            elif user_action =='3':
                dj.query_stu()
            elif user_action =='0':
                break
        else:
            print('你输入的操作有误请重新选择')

    点将小助手.py

    lis_stu = []
    dic = {'name':'姓名','age':'年龄','clazz':'学科'}
    
    def add_stu():
        print('这是一个新增操作')
        dic = {}
        dic['name'] = input('请输入姓名')
        dic['age'] = input('请输入年龄')
        dic['clazz'] = input('请输入学科')
        lis_stu.append(dic)
    
    def show_all():
        print('显示全部')
        if len(lis_stu):
            print("	%(name)s		%(age)s		%(clazz)s" % dic)
            for item in lis_stu:
                print("	%(name)s		%(age)s		%(clazz)s"%item)
        else:
            print('请先注册信息')
    
    def query_stu():
        print('查询方法')
        name_item= input('请输入要查询的武将姓名')
    
        for x in lis_stu:
            if x['name'] == name_item:
                print("	%(name)s		%(age)s		%(clazz)s"%x)
                user_input= input('请输入你想要的操作 1删除 2修改 3返回')
                if user_input in ['1','2','3']:
                    if user_input =='1':
                        lis_stu.remove(x)
                    elif user_input == '2':
                        x['name'] = my_input('请输入姓名',x['name'])
                        x['age'] = my_input('请输入年龄',x['age'])
                        x['clazz'] = my_input('请输入学科',x['clazz'])
                    elif user_input == '3':
                        break
                break
            else:
                print('没有你要的武将')
    
    
    def my_input(mess,dic_val):
        user_in = input(mess)
        if len(user_in):
            return user_in
        else:
            return dic_val
    
    def show_menu():
        print('=' * 50)
        print('''
                     1.武将招募
                     2.部队集合
                     3.武将查询
                     0.退朝
            ''')
        print('=' * 50)
  • 相关阅读:
    PDO 数据访问抽象层
    递归例子
    Windows对象操作:浏览器窗口信息
    练习题:选择器和选择好友
    搭建wamp环境,数据库基础知识
    堆表空间管理
    vc弹出USB的方法. 附试验通过的代码!
    javascript 调用C++函数
    [转]在Win7 64位注册ActiveX控件
    SetForegroundWindow的正确用法
  • 原文地址:https://www.cnblogs.com/zhangtaotqy/p/9517356.html
Copyright © 2020-2023  润新知