day05work

作业

  1. 输入姑娘的年龄后,进行以下判断:

    1. 如果姑娘小于18岁,打印“不接受未成年”

    2. 如果姑娘大于18岁小于25岁,打印“心动表白”

    3. 如果姑娘大于25岁小于45岁,打印“阿姨好”

    4. 如果姑娘大于45岁,打印“奶奶好”

      age = 18
      if age < 18:
          print('不接受未成年')
      elif age < 25:
          print('心动表白')
      elif  age < 45:
      	print('阿姨好')
      else:
          print('奶奶好')
      
  2. 预习while循环,打印1-100之间的奇数和

    count = 1
    sum1 = 0
    while count < 100:
        sum1 += count
        count += 2
    print(sum1)
    
  3. 预习while循环,猜年龄游戏升级版,有以下三点要求:

    1. 允许用户最多尝试3次

    2. 每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y, 就继续让其猜3次,以此往复,如果回答N或n,就退出程序

    3. 如果猜对了,就直接退出

      age = 18
      tag = True
      while tag:
          count = 0
      
          while count < 3:
              guess = int(input('请输入猜测的年龄: '))
              if guess == age:
                  print('恭喜你猜对了!')
                  tag = False
                  break
              elif guess > age:
                  print('对不起,猜测偏大!')
              else:
                  print('对不起,猜测偏小!')
              count += 1
          else:
              while 1:
                  choice = input('是否还想继续游戏?')
                  if choice == 'Y' or choice == 'y':
                     break
                  elif choice == 'N' or choice == 'n':
                     tag = False
                     break
                  else:
                      print('对不起输入有误!')
      
      
      
      

posted on 2019-09-11 15:45  shenblogs  阅读(170)  评论(0)    收藏  举报

导航