2.判断语句和循环语句
2.1条件判断语句
if JUDGE CONDITION:
EXE1
else:
EXE2
- example:打分(分段函数)
score = 77
if score >= 90 and score <=100 :
pirnt("A")
elif score >= 80 and score <=90 :
print("B")
elif score >= 70 and score <=80 :
print("C")
elif score >= 60 and score <=70 :
print("D")
elif score >= 0 and score <=60 :
print("F")
elif
是指的elseif,如果不是前者而是。。。
- 你甚至可以只打elif而不打else
- example:情感状况(多条件if嵌套)
xingbie = 1 #1 for man
danshen = 1 #1 for 单身
if xingbie == 1 :
print("男生")
if danshen == 1 :
print("单身男子")
else:
print("非单身男子")
else:
print("女生")
pirnt("男生") -> print
另外,example里面的if – elif – else语句的很多缩进怎么都没了?严重怀疑你这代码根本没运行过 :confused:
哎呀,wp的markdown抽风了
typo已更正
pirnt("男生") -> print
另外,example里面的if – elif – else语句的很多缩进怎么都没了?严重怀疑你这代码根本没运行过 :confused:
哎呀,wp的markdown抽风了
typo已更正