python语法
# 条件判断# if condition:# do something# else:# do somethingtotal_cost = 32.5is_vip=Trueif total_cost>30: discount=0.9 if is_vip: discount=0.8elif total_cost>50: discount = 0.8else: discount=1total_cost *=discountprint("小姐姐买水果的实际花费为:{}".format(total_cost))# 备注elif可以有0到任意多个,else可有可无,条件判断可以嵌套#一个值被当做布尔值,概念上更像有和没有的区别,比如为空的list\tuple\dict做if判断都是false# 断言age=18assert age==18 #如果等于,程序继续执行,不等于则程序报错,中断执行# 循环# for循环costs=[2,3,13,56,109]for cose in costs: print('消费{}元'.format(str(cose).center(10)))# 生成一个长度为20的随机列表import randomprint(random.randint(1,10))#1到10之间的随机数random_numbers=[]random_numbersfor=[]while