if elif 使用方法的示例

我们再来看看 if elif 使用方法的示例

age=['a','b','c','d']
if 'a' in age:
    print("you really like a!")

if 'b'in age:
    print("you really like b!")

if 'c' in age:
    print("you really like c!")

if 'e' in age:

    print("you really like e!")

输出结果如下:

you really like a

you really like b

you really like c


再看凡云阁的一段关于年龄测试的代码:

age=17
if age<2:
    price="婴儿"
elif age<4:
    price="幼儿"
elif age < 13:
    price = "儿童"
elif age<20:
    price="青少年"
elif age<65:
    price="成年人"
else:
    price="老年人"

print(F"你是{price}!")

输出结果为:

你是青少年!


本文固定链接: http://www.fanyun.ltd/2133.html | 凡云阁

fanyun
作者:fanyun 于2023年05月09日发表 & 关键词:
除非注明 否则文章均为原创,转载请注明出处: if elif 使用方法的示例 | 凡云阁

if elif 使用方法的示例:等您坐沙发呢!

发表评论

亲,不支持纯字母、符号评论哦~