快捷键
ctrl + / : 注释
ctrl + D : 复制当前行到下一行
ctrl + Z : 撤销
ctrl + shift + alt + 鼠标点选 : 多行编辑
tab : 缩进
shift + tab : 取消缩进
布尔型:
1、非0的是数字,转化为布尔值均为True
2、空字符串'' ,为False ,其余均为True
运算符的优先级:
算数 > 比较 > 赋值 > 成员 > 逻辑
赋值运算符: = += -= *= /=
成员运算符:in not in
逻辑~~~~: and or not
判断:##找对象
##############找对象########## face_score = input('颜值(0-10):') height = int(input('身高:')) weight = float(input('体重:')) sex = input('性别:') job = input('职业:') age = int(input('年龄:')) money = int(input('存款:')) hometown = input('户籍所在地:') money = int(input('存款:')) if money > 500000: sex = input('性别:') if sex == '女': height = int(input('身高:')) weight = float(input('体重:')) if height > 160 and weight < 60: face_score = input('颜值(0-10):') if face_score > 6: age = int(input('年龄:')) if 18<=age<=50: job = input('职业:') if job not in '护士,银行': print('不太合适,wx给我') else: print('职业不合适') else: print('年龄不合适') else: print('颜值不合适') else: print('身材不合适') else: print('性别不合适') else: print('你是个好人,我们不合适')
字符串的格式化:
%d 整型
%s 字符串
%f 浮点型
计算BMI
h = float(input('我的身高(m):')) w = float(input('我的体重(kg):')) BMI = w / h**2 BMI = round(BMI,1) # 保留一位小数 BMI_type='' if BMI <= 18.4: BMI_type='偏瘦' elif 18.5 <= BMI <= 23.9: BMI_type='正常' elif 24.0 <= BMI <= 27.9: BMI_type='过重' elif BMI >= 28.0: BMI_type='肥胖' print('--------------------结果如下----------------') print('计算完成,你的身体处于',BMI_type,'阶段.BMI值',BMI)
保留一位小数
方法1 :print('计算完成,你的身体处于%s阶段.BMI的值为%.1f'%(BMI_type,BMI))
方法2 :print(f'计算完成,你的身体处于{BMI_type}阶段.BMI的值为{round(BMI,1)}')
print(r'李四\n\n张三') # 添加 r \n失去作用 print('李四\n\n张三') print(rf'李四{BMI}\n\n张三')