目录python
age = 18 inp_age = input('请输入年龄>>>').strip() if inp_age.isdigit(): inp_age = int(inp_age) if age > inp_age: print('猜小了') elif age < inp_age: print('猜大了') else: print('猜对了') else: print('傻孩,年龄都输很差')
age = 18 for i in range(3): inp_age = input('请输入年龄>>>').strip() if inp_age.isdigit(): inp_age = int(inp_age) if age > inp_age: print('猜小了') elif age < inp_age: print('猜大了') else: print('猜对了') break else: print('傻孩,年龄都输很差')
age = 18 count = 0 tag = True while tag: count += 1 inp_age = input('请输入猜想年龄>>>').strip() if inp_age.isdigit(): inp_age = int(inp_age) if age > inp_age: print('猜小了') elif age < inp_age: print('猜大了') else: print('猜对了') break else: print('傻孩,年龄都输很差') if count == 3: choice = input('是否继续猜想,继续请按Y or y ,任意键退出').strip().lower() if choice != 'y': tag = False else: continue
要求:git
import random #导入随机库 prize_dic = {0: '气球', 1: '女友', 2: '劳斯莱斯', 3: '宝马', 4: '牛逼', 5: '坦克', 6: '大炮', 7: '飞机'} # type:dict # 奖品单 user_price_dic = {} # type:dict age = random.randint(18,19) # 让年龄随机18或者19 count = 0 while count<3: count+=1 inp_age = input('请输入猜想的年龄>>').strip() if not inp_age.isdigit(): print('输入错误,请输入数字') continue inp_age= int(inp_age) inp_age = int(inp_age) if age > inp_age: print('猜小了') elif age < inp_age: print('猜大了') else: print('猜对了') for k, v in prize_dic.items(): print(k, v) for i in range(2): choice_prize = input('请输入奖品编号>>>').strip() if not choice_prize.isdigit(): print('撒掉,一边弯曲') continue choice_prize = int(choice_prize) prize = prize_dic[choice_prize] print('得到了', prize) if prize not in user_price_dic: user_price_dic[prize] = 1 else: user_price_dic[prize] += 1 print('奖品以下', user_price_dic) break