小纸条100号
小纸条100号
发布于 2025-11-12 / 0 阅读
0

003python语言的流程控制

1、分支语句

if

score = 78
if score >= 90:
    print("优秀")
if score < 60:
    print("还需努力")
if (score >=60) and (score < 90):
    print("中等生,加油")

if else


score = 55

if score>60:
    if score>=90:
        print("优秀")
    else:
        print("中等生,加油")
else:
    print("还需努力")

if elif else

score = 99

if score>=90:
    print("优秀")
elif score>=60:
    print("中等生,加油")
else:
    print("还需努力")

2、循环语句

while循环

index = 1
sum = 0
while index < 100:
    sum += index
    index+=1
print(sum)
#---------
index = 1
sum = 0
while True:
    if index>99:
        break
    sum += index
    index+=1

print(sum)

for循环

for s in "hello":
    print(s)

for s in [1,2,3,4,5]:
    print(s)

3、跳转语句

break

continue