• day07(作业)


    定义变量

    age = 18  # 给定年龄
    age_count = 0  # 计算次数
    prize_dict = {
        '0': "芭比娃娃",
        '1': "变形金刚",
        '2': "psp游戏机",
        '3': "奥特曼",
        '4': "遥控飞机",
        '5': "chongqiwawa",
    }  # 奖品选取
    prize_msg = '''
    0 芭比娃娃
    1 变形金刚
    2 psp游戏机
    3 奥特曼
    4 遥控飞机
    5 chongqiwawa
    '''  # 打印奖品目录
    get_prize_dict = {}  # 获取的奖品信息
    

    核心代码if判断

    age_inp = input('请输入你的年龄')
    if not age_inp.isdigit():
      print(f'你的年龄是{age_inp}吗')/
    age_inp_int=int(age_inp)
    if age_inp_int > age:
        print('猜大了')
    elif age_inp_int < age:
        print('猜小了')
    else:
        print('猜对了')
    

    while 循环 可以输入3次

    while age_count<3:
      age_inp = input('请输入你的年龄')
      if not age_inp.isdigit():
        print(f'你的年龄是{age_inp}吗')
      age_inp_int=int(age_inp)
      if age_inp_int > age:
          print('猜大了')
      elif age_inp_int < age:
          print('猜小了')
      else:
          print('猜对了')
    age_count+=1
    
    	
    

    奖品派发机制

    print(f'奖品如下{prize_msg}')
    prize_choice = input('输入选择的奖品:')
    prize = prize_dict[prize_choice]
    if prize in get_prize_dict:
      get_prize_dict[prize] += 1
    else:
      get_prize_dict[prize] = 1
    print(f'恭喜你获得奖品 {prize}')
    

    while循环可选取两次奖品

    priz_count=0
    while prize_count<2:
      print(f'奖品如下{prize_msg}')
      prize_choice = input('输入选择的奖品:')
      prize = prize_dict[prize_choice]
      if prize in get_prize_dict:
        get_prize_dict[prize] += 1
      else:
        get_prize_dict[prize] = 1
      print(f'恭喜你获得奖品 {prize}')
      prize_count+=1
    print(f'总共获得奖品为:{get_prize_dict}')
    

    汇总

    age = 18  # 给定年龄
    age_count = 0  # 计算次数
    prize_dict = {
        '0': "芭比娃娃",
        '1': "变形金刚",
        '2': "psp游戏机",
        '3': "奥特曼",
        '4': "遥控飞机",
        '5': "chongqiwawa",
    }  # 奖品选取
    prize_msg = '''
    0 芭比娃娃
    1 变形金刚
    2 psp游戏机
    3 奥特曼
    4 遥控飞机
    5 chongqiwawa
    '''  # 打印奖品目录
    get_prize_dict = {}  # 获取的奖品信息
    while age_count<3:
        age_inp = input('请输入你的年龄')
        if not age_inp.isdigit():
            print(f'你的年龄是{age_inp}吗')
        age_inp_int = int(age_inp)
        if age_inp_int > age:
            print('猜大了')
        elif age_inp_int < age:
            print('猜小了')
        else:
            print('猜对了')
            prize_count=0
            while prize_count<2:
                print(f'奖品如下{prize_msg}')
                prize_choice = input('输入选择的奖品:')
                prize = prize_dict[prize_choice]
                if prize in get_prize_dict:
                    get_prize_dict[prize] += 1
                else:
                    get_prize_dict[prize] = 1
                print(f'恭喜你获得奖品 {prize}')
                prize_count+=1
            print(f'总共获得奖品为:{get_prize_dict}')
            break
        age_count+=1
    
    
    
  • 相关阅读:
    后缀表达式
    Linux中的硬链接和软链接
    C++中const总结
    atexit()函数
    Linux中的0号进程和1号进程
    什么是可重入函数和不可重入函数
    在线(Online)算法
    PHP验证IP地址输入的准确性:数组数值验证
    PHP网页计时工具——SESSION问题
    软件版本号命名规则
  • 原文地址:https://www.cnblogs.com/luocongyu/p/11529586.html
Copyright © 2020-2023  润新知