zoukankan      html  css  js  c++  java
  • Python——if、elif、else语句

    一、流程分支 

        1. 单分支:

          例1:建立一个判断,输入年龄,判断年龄是否大于23,如果大于23,打印结果:‘It is time to find a bf’:

       

    1 age_of _you=int(input('please input your name:'))
    2 age_of _you=25
    3 if age_of _you > 23:
    4     print('it is time to find a bf)

        2.双分支:

        例2:输入用户名和密码,当用户名和密码都正确时欢迎用户,否则提示错误

      

     1 _username='shanshan'
     2 _password='123456'
     3 
     4 username=input('pleaue input your name:')
     5 password=input('pleaue input your password:')
     6 
     7 if _username==username and _password==password:
     8     print('welcome',username)
     9 else:
    10     print('worong username or password')

      3.分支下继续分支

      例3:输入年龄,性别,名字,如果是女生,年龄<28,输出‘I love girls’,年龄>28,输出姐弟恋也很好哦,如果是男生,输出一起来搞基吧

      

     1 name=input('name:')
     2 sex=input('sex:')
     3 age=int(input("age:"))
     4 
     5 if sex=='f':
     6     if age<28:
     7         print('I love girls')
     8     else:
     9         print('姐弟恋也很好哦')
    10 else:
    11     print('一起来搞基吧')

     4. 多分支

     例4.练习:对成绩等级,A:90~100,B:80~89,C:60~79,D:40~59,E:<39

     1 grade=int(input('grade:'))
     2 
     3 if grade>=90:
     4     print('A')
     5 elif grade>=80:
     6     print('B')
     7 elif grade>=60:
     8     print('C')
     9 elif grade>=40:
    10     print('D')
    11 else:
    12     print('E')
  • 相关阅读:
    C#将List<T>转化为DataTable
    SqlServer常用内置函数
    C#索引器
    验证Textbox的字符长度
    WM消息对应的Message消息中的Lparam和WParam
    对窗体操作的WM消息
    DllImport使用
    C#获取当前路径的七种方法
    注册ActiveX控件
    [转]VS2010中水晶报表安装应用及实例
  • 原文地址:https://www.cnblogs.com/xwxs/p/9193420.html
Copyright © 2011-2022 走看看