标签:python流程处理 python please number
python流程处理
1.流程处理if...else
#!/bin/bash/env python #_*_ coding:utf-8 _*_ #python version :python3.6 import getpass n1 = "abc" p1 = "123" name = input("input your name:") passwd = getpass.getpass("input your passwd:") if name == n1 and passwd == p1: print("welecome login !") else: print("user or pass is incorrect")
2.流程处理if...elif...elif...else
#!/bin/bash/env python #_*_ coding:utf-8 _*_ #python version:3.6 n1 = 21 name = int(input("please input the number which you want to:")) if name == n1: print("you are too smart!") elif name < 21: print("is too small!") else: print("it is too big!")
3.for循环
例1: # 循环10个数字 i = 1 for i in range(10): print(i) 例2: #猜年龄优化for...break #可以输入10次机会,输入正确就退出。 n1 = 21 for i in range(10): name = int(input("please input the number which you want to:")) if name == n1: print("you are too smart!") break; elif name < 21: print("is too small!") else: print("it is too big!")
4.while循环
#!/bin/bash/env python #_*_ coding:utf-8 _*_ #python version:3.6 例1 #循环数字,当循环10的时候退出 count = 0 #设置计数器 while True: print("print:" ,count) count +=1 if count == 10: print("loop completed") break; #跳出循环 例2 #猜年龄游戏,可以输入10次,但是输错3次就退出。 n1 = 21 count = 0 while True: if count < 3: name = int(input("please input the number which you want to:")) if name == n1: print("you are too smart!") break; elif name < 21: print("is too small!") else: print("it is too big!") else: print("you are too failed!") break; count += 1
本文出自 “506554897” 博客,请务必保留此出处http://506554897.blog.51cto.com/2823970/1906437
标签:python流程处理 python please number
原文地址:http://506554897.blog.51cto.com/2823970/1906437