Super introduction to Python (3)__Get started quickly and master Python

# 11.if statement
is_student = True  # bool类型
is_teacher = False

if is_student:
    print("请到操场集合")
elif is_teacher:
    print("请到办公室集合")
else:
    print("请离开学校")
print("谢谢合作")
"""
请到操场集合
谢谢合作
"""
Exercise: There is a house worth a million dollars. When you meet a good buyer, you can make a profit of 20%; otherwise, it is 10%; 
output the profit obtained.
price = 1000000
is_good_buyer = True
if is_good_buyer:
    gain_profit = price * 0.2
else:
    gain_profit = price * 0.1

print(f'You will getting ${gain_profit}')
# 12. Logical operators (and, or, not) priority: not > and > or
has_high_income = True
has_good_credit = False
has_criminal_record = False
if (has_high_income or has_good_credit) and not has_criminal_record:  # (T or F) and T
    print("允许贷款")
else:
    print("不允许贷款")
"""
允许贷款
"""
# 13. Comparison operators (>; >=; <; <=; !=; ==)
temperature = int(input("请输入今天的气温:"))
if temperature >= 30:
    print("今天是炎热的一天")
elif 30 > temperature > 20:
    print("今天是温暖的一天")
else:
    print("今天要加衣服了")
"""
请输入今天的气温:25
今天是温暖的一天
"""
Exercise: Your name must be no less than 2 characters long and no longer than 20 characters; a name 
that meets the rules is a good name.
name = input("请输入你的名字: ")
if len(name) < 2:
    print("你的名字长度必须大于2个字符")
elif len(name) > 20:
    print("你的名字长度必须小于20个字符")
else:
    print("这是一个好名字")
# 14. Use the knowledge learned to build a weight converter applet
weight = int(input("weight: "))
unit = input("(L)bs or (K)g: ")
if unit.upper() == "L":
    converted = weight * 0.45
    print(f"You are {converted} kilos")
elif unit.upper() == "K":
    converted = weight / 0.45
    print(f"You are {converted} pounds")
else:
    print("Print error!")
"""
weight: 120
(L)bs or (K)g: l
You are 54.0 kilos
"""

Guess you like

Origin blog.csdn.net/qq_57233919/article/details/132783723