zoukankan      html  css  js  c++  java
  • if条件判断和while循环

    1. 输入姑娘的年龄后,进行以下判断:
    1. 如果姑娘小于18岁,打印“不接受未成年”
    2. 如果姑娘大于18岁小于25岁,打印“心动表白”
    3. 如果姑娘大于25岁小于45岁,打印“阿姨好”
    4. 如果姑娘大于45岁,打印“奶奶好”

    1 age=input('请输入年龄>>>:').strip()
    2 age=int(age)
    3 if age>45:
    4     print('奶奶好')
    5 elif age>25:
    6     print('阿姨好!!')
    7 elif age>18:
    8     print('心动表白')

    2. 预习while循环,打印1-100之间的奇数和

    1 count=1
    2 get_sum=0
    3 while count<100:
    4     get_sum+=count
    5     count += 2
    6 print(get_sum)

    3. 预习while循环,猜年龄游戏升级版,有以下三点要求:
       1. 允许用户最多尝试3次
       2. 每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y, 就继续让其猜3次,以此往 复,如果回答N或n,就退出程序
            3. 如果猜对了,就直接退出

     1 count=0
     2 actual_age=18
     3 while True:
     4     if count==3:
     5         choice=input('你3次都没有猜对,还要继续玩吗?(y/n)').strip().lower()
     6         if choice=='y':
     7            count = 0
     8            continue
     9         elif choice=='n':
    10            break
    11         else:
    12             print('哥,好好输行吗?')
    13             continue
    14     age=input('你猜英俊潇洒的我年龄是多少?>>>:').strip()
    15     count+=1
    16     if not age.isdigit():
    17         print('智障,输入数字你都不懂吗?')
    18         continue
    19 
    20     age = int(age)
    21     if age > actual_age:
    22         print('你看我这气质和精神气,有那么大么?')
    23 
    24     elif age < actual_age:
    25         print('你见过这么小的孩子,像我这般成熟吗?')
    26     else:
    27         print('你他妈终于猜对了!')
    28         break
    View Code
  • 相关阅读:
    python,生产环境安装
    neo4j 图数据库
    RNN系列
    机器学习关于AUC的理解整理
    fensorflow 安装报错 DEPENDENCY ERROR
    dubbo Failed to check the status of the service com.user.service.UserService. No provider available for the service
    使用hbase遇到的问题
    MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk
    gradle 安装
    jenkins 安装遇到的坑
  • 原文地址:https://www.cnblogs.com/zhangchaocoming/p/11507497.html
Copyright © 2011-2022 走看看