day07 (work)

Define the variable

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 = {}  # 获取的奖品信息

Determine if the core code

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('猜对了')

3 can be input while loop

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

    

Prize distribution mechanism

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 loop can select two prizes

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}')

Gather

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

Guess you like

Origin www.cnblogs.com/luocongyu/p/11529586.html