Python 控制流if-else,循环

知识点
if 语句
else 语句
真值检测
while循环

输入一个数判断是否大于100
其中else if 可以简写成elif

#!/bin/bash/env python3
num=float(input("enter :"))
if num<100:
    print("less 100")
elif num>100:
    print("more 100")
else:
    print("equal 100")

这里写图片描述
真值检测

if x:
    pass

while循环

按顺序打印 0 到 10 的数字

n=0
while n<11:
    print(n)
    n+=1

这里写图片描述

打印100之前的斐波那契数列

这个数列前两项为 1,之后的每一个项都是前两项之和。所以这个数列看起来就像这样:1,1,2,3,5,8,13 ……

a,b=0,1
while b<100:
    print(b)
    a,b=b,a+b

这里写图片描述

猜你喜欢

转载自blog.csdn.net/yu876876/article/details/81304332
今日推荐