流程控制
一、分支结构
1、if else
x = int(input("please input x:"))
y = int(input("please input y:"))
if(not x>=90 and not y>=90):
print("A")
else
print("B")
2、elifd 用法
if(a >=90):
print("a>=90")
elif (a >=80):
print("90>=a>=80")
else
print("a<80")
三、for 循环
for 循环遍历序列,如一个列表或一个字符
语法:
for 参数 in 来源
for x in "abcd":
print("hello world")
for x in "abcd":
print(x,"hello world")
for x in [0,1,2,3,4,5,6]:
print(x,"hello world")
rang[i,j[,步进值]]
for i in range(2,15,3):
print (i)
结果
C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\python.exe C:/Users/Administrator/PycharmProjects/test/test.py
2
5
8
11
14
Process finished with exit code 0
s = ["hello", "haha", "gogo"]
for x in range(len(s)):
print(x, s[x])
C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\python.exe C:/Users/Administrator/PycharmProjects/test/test.py
0 hello
1 haha
2 gogo
Process finished with exit code 0