一、流程控制---if

  1.if条件判断

  

age=18
hight=1.70
sex="female"
is_beautiful=True
if sex=="female" and age>16and age<20 and is_beautiful \
        and hight>1.60 and hight<1.75:
    print("表白。。。。")

  2.if+else

hight=1.70
sex="female"
is_beautiful=True
if sex=="female" and age>16and age<20 and is_beautiful \
        and hight>1.60 and hight<1.75:
    print("表白。。。。")
    if is_beautiful:
        print("在一起。。。")
    else:
        print("什么爱情不爱情""和我有半毛钱关系")

  3.if的嵌套:

#语法三:if 的嵌套
age=18
hight=1.70
sex="female"
is_beautiful=True
if sex=="female" and age>16and age<20 and is_beautiful \
        and hight>1.60 and hight<1.75:
    print("表白。。。。")
    if is_beautiful:
        print("在一起。。。")
    else:
        print("什么爱情不爱情""和我有半毛钱关系")
else:
    print("阿姨好。。。")
print(" code ...")

  4.if-elif的运用:

如果 成绩>=90,那么:优秀

如果 成绩>=80且<90,那么:良好

如果 成绩>=70且<80,那么:普通

其他情况:很差
"""score=input("输入成绩:")
score=int(scar)
if scar>=90:
    print("优秀")
elif score>=80:
    print("良好")
elif score>=70:
    print("普通")
else:
    print("极差")"""

 二、流程控制--while

  1.while循环又称为条件循环

  

   while条件循环
"""

while True:
    name=input("please input yourname:")

    password=input("please input your passwor;")

    if name=="adb" and password=="123":

        print("login successful")

    else:

         print("username or password error")

  2.while+条件结束

  

tag=True
while tag:
    name=input("please input yourname:")

    password=input("please input your passwor;")

    if name=="adb" and password=="123":

        print("login successful")

        tag=False

    else:

         print("username or password error")

  3.while+break:退出本层循环

  

while True:
    name = input("please input yourname:")

    password = input("please input your passwor;")

    if name == "adb" and password == "123":

        print("login successful")

        break

  4.while+continue:终止本次循环,进行下次循环,跳过了本次循环之后的代码

  

ount=0
while count<6:
    if count==4:
       count+=1
    continue
    print(count)
    count+=1

 5.while+else:当while循环正常执行完,中间没有break中止的话,执行else

  

# ---while-else----
count = 1
while count < 6:
    if count == 4:
        count += 1
        continue

    print(count)
    count += 1
else:
    print("while-else最后else的代码")

  三、流程控制--for

  for循环又称为迭代循环
  for可以不依赖于索引取指,是一种通用的循环取指方式
  循环次数是由被循环对象包含值的个数决定的,而while的循环次数是由条件决定的

  for+break

  for+continute

  for+else

  和while一样的用法

  1.0 range() 》》》通常用于取值不(依赖索引)

  

range(1,5)
>>>1 2 3 4#g顾头不顾尾,
所以只能取到

range(5)
>>>1 2 3 4

range(1,5,2)  #补偿 ,每隔两个取值#i = i + 2
>>>1 3

  

  2.0嵌套循环:

for i in range(1,10):
        for j in range(1,i+1):        print("%s*%s=%s" %(i,j,i*j,end="")     print()#换行

  本章练习:

 .练习,要求如下:

  1.1用户登录:

  

name=input("please your name:")
password=input("please your password:")

if name =="egon" and password=="123456":
    print("login successful....")
    break
else:
    print("name or password error....")

  1.2管理员登录系统:

  

egon --> 超级管理员
tom  --> 普通管理员
jack,rain --> 业务主管
其他 --> 普通用户
ame=input("请输入名字:")
if name=="egon":
    print("超级管理员")
elif name=="tom":
    print("普管理员")
elif name=="jick,rain":
    print("业务主管")
else:
    print("普通用户")

  1.3

  

 如果:今天是Monday,那么:上班
 # 如果:今天是Tuesday,那么:上班
 # 如果:今天是Wednesday,那么:上班
 # 如果:今天是Thursday,那么:上班
 # 如果:今天是Friday,那么:上班
 # 如果:今天是Saturday,那么:出去浪
 # 如果:今天是Sunday,那么:出去浪

 """
 """
 today_is=input("今天是礼拜几:")
 if  today_is=="monday" or today_is=="tuestday" or today_is=="wedneesday"or \
         today_is=="thursday"or today_is=="friday":
     print("working...")
 elif today_is=="sunday" or today_is=="saturday":
     print("playing...")
 else:
     print("必须输入:"
         "monday"
     "Tuesday",
     "Wednesday",
     "Thursday",
     "Friday",
     "Saturday",
     "Sunday"   )

  2.1.while循环练习题
        1 循环验证用户输入的用户名与密码
        2 认证通过后,运行用户重复执行命令
3 当用户输入命令为时,则退出整个程序

  

name = "egon"
password = "123456"

count = 0
while True:

    inp_name = input("please your name:")
    inp_password = input("please your password:")
    if name == inp_name and password == inp_password:
        print("login successful....")
        print("""
        1 取钱
        2 存款
        3 退出

        """)
        while True:
            choice = input("please input your choice")
            if choice == "1":
                print("取钱")
            elif choice == "2":
                print("存钱")
            elif choice == "3":
                break
            else:
                print("你的输入有误,请重新输入")
    else:
        print("name or password error....")
        count += 1
        if count == 3:
            break

  2.1 迭代式循环:for for in range():作业九九乘法表

  

for i in range(1,10):        for j in range(1,i+1):        print("%s*%s=%s" %(i,j,i*j,end="")     print()

 

1*1=1
2*1=22*2=4
3*1=33*2=63*3=9
4*1=44*2=84*3=124*4=16
5*1=55*2=105*3=155*4=205*5=25
6*1=66*2=126*3=186*4=246*5=306*6=36
7*1=77*2=147*3=217*4=287*5=357*6=427*7=49
8*1=88*2=168*3=248*4=328*5=408*6=488*7=568*8=64
9*1=99*2=189*3=279*4=369*5=459*6=549*7=639*8=729*9=81

  

2.2 制作金字塔

  

  感谢您的阅览,有不足之处还请之处,共同学习! 内容持续更新中。。。

函数的if--while流程控制的更多相关文章

  1. 「C」 函数、运算、流程控制

    一.函数 (一)什么是函数 任何一个C语言程序都是由一个或者多个程序段(小程序)构成的,每个程序段都有自己的功能,我们一般称这些程序段为“函数”. (二)函数的定义 目的:将一个常用的功能封装起来,方 ...

  2. Postman高级应用——流程控制、调试、公共函数、外部数据文件

    postman客户端下载地址:https://www.getpostman.com/apps 目录 流程控制 调试 公共函数 外部数据文件 流程控制 流程控制简言之就是设置接口的执行顺序,流程控制只有 ...

  3. MySQL-5-TCL,视图,变量,存储过程和函数,流程控制

    TCL:Transaction Control Language事务控制语言 TCL 事务的特点 acid: 原子性(Atomicity),一致性(Consistency),隔离性(isolation ...

  4. EventProxy流程控制

    EventProxy流程控制 EventProxy是一个通过控制事件触发顺序来控制业务流程的工具. 1. 利用事件机制解耦复杂业务逻辑2. 移除被广为诟病的深度callback嵌套问题3. 将串行等待 ...

  5. Scala深入浅出实战经典-----002Scala函数定义、流程控制、异常处理入门实战

    002-Scala函数定义.流程控制.异常处理入门实战 Scala函数定义 语句结束无分号 定义无参函数 def 函数名称(参数名称:参数类型)[:Unit=]{ 函数体 } 老师的代码 我的实际代码 ...

  6. javascript之流程控制 和函数的容易忽略点

    1.流程控制 1> for in  仅用于 对象的遍历: var box={ "name":'小红', 'age':18, 'height':165 }; for(var b ...

  7. awk(流程控制、内置变量、内置函数、数组)

    摘自:http://bbs.51cto.com/thread-883948-1-1.html awk(流程控制.内置变量.内置函数.数组) ... 参考其他的资料,给大家看看.一.awk流程控制语句 ...

  8. Go 从入门到精通(三)字符串,时间,流程控制,函数

    一.strings和strconv的使用 strings strings.HasPrefix(s string,preffix string) bool:判断字符串s是否以prefix开头 stirn ...

  9. MySQL自定义函数用法详解-复合结构自定义变量/流程控制

    自定义函数 (user-defined function UDF)就是用一个象ABS() 或 CONCAT()这样的固有(内建)函数一样作用的新函数去扩展MySQL. 所以UDF是对MySQL功能的一 ...

  10. JAVA之旅(二)——if,switch,for,while,do while,语句嵌套,流程控制break , continue ,函数,重载的示例总结

    JAVA之旅(二)--if,switch,for,while,do while,语句嵌套,流程控制break , continue ,函数,重载的示例总结 JAVA的思想真的很重要,所以要专心的学-- ...

随机推荐

  1. 使用opencv进行简单的手势检测[by Python]

    代码参考于:https://github.com/rainyear/lolita/issues/8 简单的手势识别,基本思路是基于皮肤检测,皮肤的颜色在HSV颜色空间下与周围环境的区分度更高,从RGB ...

  2. .NET CORE微服务中CONSUL的相关使用

    .NET CORE微服务中CONSUL的相关使用 1.consul在微服务中的作用 consul主要做三件事:1.提供服务到ip的注册 2.提供ip到服务地址的列表查询 3.对提供服务方做健康检查(定 ...

  3. Qt License 解读

    对于桌面和移动平台应用 官方说明如下 Qt for Application Development lets you create applications for desktop and mobil ...

  4. open-falcon自定义push数据无法在grafana显示

    使用open-falcon自定义push数据,在open-falcon中数据能正常显示,而在grafana中添加监控项时却无法显示. 由上述现象可判断可能是由于open-falcon的api组件有问题 ...

  5. git 命令积累

    git status # 查看仓库的状态 git add . # 监控工作区的状态树,使用它会把工作时的所有变化提交到暂存区,包括文件内容修改(modified)以及新文件(new),但不包括被删除的 ...

  6. 转 HttpClient 设置连接超时时间

    要: HttpClient 4.5版本升级后,设置超时时间的API又有新的变化,请大家关注. HttpClient升级到4.5版本后,API有很多变化,HttpClient 4之后,API一直没有太稳 ...

  7. OC调用c++函数

    1.调用的时候我明明改成了 .mm  , 也添加了libstdc++.dylib  调用自己(xcode )写的(cocoa static lib )c++  ,编译总是报找不到库里的函数, 最后我在 ...

  8. git revert用法以及与git reset的区别

    git revert用法 git revert 撤销 某次操作,此次操作之前和之后的commit和history都会保留,并且把这次撤销 作为一次最新的提交 * git revert HEAD     ...

  9. spring boot 操作MySQL pom添加的配置

    1 在项目中的pom.xml配置文件添加依赖 <!--MySQL依赖 --> <dependency> <groupId>mysql</groupId> ...

  10. Shell命令-文件及目录操作之ls、cd

    文件及目录操作 - ls.cd 1.ls:列出目录的内容及其内容属性信息 ls命令的功能说明 ls命令用于列出目录的内容及其内容属性信息. ls命令的语法格式 ls [OPTION]... [FILE ...