今日起得比较早,持续练习代码,学习代码,到了一个编程领域的概念,操作数,运算符和表达式,然后勤加练习
'''
操作数:变量或数据
运算符:执行特殊操作的符号
赋值运算符:把数据赋予变量的符号
=
算术运算符:对操作数执行运算返回运算结果的符号
+ - * / % // **
比较运算符:对操作数执行比较返回真假的符号(不同数据类型操作数比较毫无意义)
== != < <= > >=
布尔运算符:对返回真假的表达式或操作数执行运算并返回真假的符号
and or not
表达式:一段可以参与运算的结构,由操作数和运算符构成
'''
# 赋值运算符
a = 10
b = 2
# 算术运算符
print('--------算术运算符---------')
print('+:', a+b)
print('-:', a-b)
print('*:', a*b)
print('/:', a/b)
print('%:', a % b)
print('//:', a//b)
print('**:', a**b)
# 比较运算符
print('--------比较运算符---------')
print(a == b)
print(a != b)
print(a < b)
print(a <= b)
print(a > b)
print(a >= b)
# 这里注意,不同类型变量比较毫无意义,这是毫无意义的比较(甚至可能会存在异常)
print('主' == 6)
print('主' != 6)
# 布尔运算符
print('--------布尔运算符---------')
print(True and True) # and 必须满足两边返回的结果都为真才能返回真
print(False and True)
print(True or False) # or 必须满足至少一边返回的结果为真才能返回真
print(False or False)
print(not True) # not 颠倒是非黑白真假
print(not False)
# 练习
print('--------练习---------')
'''
根据相亲标准,判断相亲条件是否符合?
栋栋的相亲标准是
- 160cm 以上的女孩
- 年薪 10w 及以上 或者 家里有矿 或者 家里有厂 的女孩
- 喜欢 唱 跳 rap 篮球 就是那种酷酷得女孩——也就是假小子
- 经常锻炼有腹肌和胸肌 让栋栋有安全感的女孩
'''
# 创建一个判断函数打印真假
def yes_or_no(name, height, year_salary, like_song, like_jump, like_rap, like_basketball, exercise_abdominal_muscels, exercise_chest_muscels):
print('通过判断', name, '对象为:', height > 160.0 and (year_salary >= 100000.0 or home_rich or home_factory)
and like_song and like_jump and like_rap and like_basketball and exercise_abdominal_muscels and exercise_chest_muscels)
# 这是对象的标准
name = 'duo'
height = 160.1
year_salary = 100000.0
home_rich = False
home_factory = False
like_song = True
like_jump = True
like_rap = True
like_basketball = True
exercise_abdominal_muscels = True
exercise_chest_muscels = True
# 使用函数判断是否符合标准
yes_or_no(name, height, year_salary, like_song, like_jump, like_rap,
like_basketball, exercise_abdominal_muscels, exercise_chest_muscels)
# 这是对象的标准
name = 'lili'
height = 159.999
year_salary = 100000.0
home_rich = False
home_factory = False
like_song = True
like_jump = True
like_rap = True
like_basketball = True
exercise_abdominal_muscels = True
exercise_chest_muscels = True
# 使用函数判断是否符合标准
yes_or_no(name, height, year_salary, like_song, like_jump, like_rap,
like_basketball, exercise_abdominal_muscels, exercise_chest_muscels)
参考
6 布尔类型和条件表达式_哔哩哔哩_bilibili
7 条件表达式题目讲解_哔哩哔哩_bilibili
Python-Core-50-Courses/第04课:Python语言元素之运算符.md at master · jackfrued/Python-Core-50-Courses · GitHub