“”“Python if & while”""
1,if函数语句支持的数学条件
#函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段。
#== != > < >= <=
import random
age = random.randint(1, 101)
time = 100 - age
if age == time:
print(‘人到半百心犹盛’)
if age > time:
print(‘老当益壮气亦足’)
if age < time:
print(‘年少勇闯天下难’)
#这结果就是完全随机的了
2,list对比
test_num01 = [1, 3, 4, 5, 9]
test_num02 = [1, 3, 4, 5, 8]
if test_num01 == test_num02:
print(‘两个列表相等’)
if test_num01 != test_num02:
print(‘两个列表不相等’)
#两个列表不相等
3,字典对比
test_dict01 = {‘fruit’: ‘apple’, ‘plant’: ‘white poplar’}
test_dict02 = {‘plant’: ‘white poplar’, ‘fruit’: ‘apple’}
if test_dict01 == test_dict02:
print(‘两个字典相同’)
elif test_dict01