• 2019.9.11作业


    1. 输入姑娘的年龄后,进行以下判断:
      1. 如果姑娘小于18岁,打印“不接受未成年”
      2. 如果姑娘大于18岁小于25岁,打印“心动表白”
      3. 如果姑娘大于25岁小于45岁,打印“阿姨好”
      4. 如果姑娘大于45岁,打印“奶奶好”
    age = input('请输入年龄:')
    age_int = int(age)
    
    if age_int < 18:
        print('不接受未成年')
    elif age_int < 25:
        print('心动表白')
    elif age_int <45:
        print('阿姨好')
    else:
        print('奶奶好')
    
    1. 预习while循环,打印1-100之间的奇数和
    count = 1
    sum_num = 0
    while count <100:
        sum_num += count
        count +=2
    print(sum_num,count)
    
    1. 预习while循环,猜年龄游戏升级版,有以下三点要求:
      1. 允许用户最多尝试3次
      2. 每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y, 就继续让其猜3次,以此往复,如果回答N或n,就退出程序.
      3. 如果猜对了,就直接退出
    count = 0
    while count < 3:
        age = input('please guess the age of nick:')
        age_int = int(age)
    
        if count == 2:
            que = input('''
    do you want to continue?
    press Y/y to continue,press N/n to end the game:''')
    
            if que == 'Y' or que == 'y':
                count = 0
                continue
            elif que == 'N' or que == 'n':
                print('thank you ')
                break
            else:
                input('please make a choice:Y/N?')
                count = 0
                continue
    
        if age_int < 30:
            print('too young')
        elif age_int > 30:
            print('too old')
        else:
            print('bingo', end='
    ''the game is done.')
            break
        count += 1
    

    最后一题.当用户输入非y/n时,提醒一次,再次输入,重新任意字符开始游戏,y/n判断未成功加入循环,未完待续

  • 相关阅读:
    ubuntu下使用golang、qml与ubuntu sdk开发桌面应用 (简单示例)
    Go Revel 学习指南
    Go Revel
    Go Revel
    Go Revel
    Go Revel
    Go Revel
    Go Revel
    Go Revel
    Go Revel
  • 原文地址:https://www.cnblogs.com/agsol/p/11507884.html
Copyright © 2020-2023  润新知