#if语句嵌套
if int(input("输入身高=")) > 120 : if int(input("输入vip等级=")) > 3: print("免票") else : print("买票") else : print("免票")
#continue 参与循环
i = 1 while i <=5 : if i ==3 : print("第3个苹果坏了,我要吃下一个") i += 1 continue print(f"这是第{i}个苹果") i +=1
#for循环累加
sum = 0 for i in range(1,101) : sum += i print(sum)
#偶数累加
a = 0 i = 1 while i <= 100 : if i %2 == 0 :#选出所有偶数 a += i i +=1 print(a)
#输出*方阵
i = 0 while i < 5 :#打印5行 j = 0 while j < 5 :#打印出一行 print("*",end = " ") j += 1 print("")#换行符 i +=1
#输出*三角阵
i = 0 while i < 5 :#打印5行 j = 0 while j < i + 1 :#设置每一行打印数量 print("*",end = " ") j += 1 print("")#换行符 i +=1
#输出9*9乘法表
i = 1 while i <=9 : j = 1 while j < i + 1 : print(f"{j}*{i}=",i*j, end = "\t") j += 1 print("") i +=1
标签:end,python,代码,打印,int,while,print,sum From: https://www.cnblogs.com/Gavin-bk/p/18077224