程序流程控制
程序设计的基本结构
程序流程图

顺序结构
#将三角形三条边长,求面积
import math
a = int(input("请输入边长a:"))
b = int(input("请输入边长b:"))
c = int(input("请输入边长c:"))
#求取半边长
p = (a + b + c)/2
#计算面积
s = math.sqrt(p*(p-a)*(p-b)*(p-c))
print(f"面积是{s}")
选择结构
选择结构/分支结构

#根据年龄判断能不能上网
age = int(input("please input your age:"))
if 18<=age<100:
print("可以上网")
elif 0<=age<18:
print("不能上网")
else:
print("输入不合法")
#####三元运算
a=10
b=20
c = a>b and a or b
c = a if a>b else b
循环结构
循环结构(for)

num = 1
for i in 'python':
print(f"第{num}个字符为:{i}")
num+=1
输出为:
第1个字符为:p
第2个字符为:y
第3个字符为:t
第4个字符为:h
第5个字符为:o
第6个字符为:n
###登陆三次机会
for i in range(3):
usrname = input("请输入用户名:")
password = input("请输入密码:")
if usrname == 'root'and password == '123456':
print ("登陆成功")
break
else:
print(f"登陆失败,您还剩{2-i}次机会")
else:
print("三次机会已用完")
循环结构(while)

#求取1-10的和
count = 1
s = 0
while count < 11:
s += count
count += 1
print(f"1-10的和为{s}")
输出:
1-10的和为55
# ##用户验证
i = 0
while i <3:
usrname = input("请输入用户名:")
password = input("请输入密码:")
if usrname == 'root' and password == '123456':
print ("登陆成功")
break
else:
print(f"登陆失败,您还剩{2-i}次机会")
i += 1
else:
print("三次机会已用完")