• Python超入门(3)__迅速上手操作掌握Python


    # 11.if语句
    1. is_student = True # bool类型
    2. is_teacher = False
    3. if is_student:
    4. print("请到操场集合")
    5. elif is_teacher:
    6. print("请到办公室集合")
    7. else:
    8. print("请离开学校")
    9. print("谢谢合作")
    10. """
    11. 请到操场集合
    12. 谢谢合作
    13. """
    练习:有一栋价值一百万美元的房子,,当你遇上一个好买家时,可以获得20%的利润;否则为10%;
    输出获得的利润。
    1. price = 1000000
    2. is_good_buyer = True
    3. if is_good_buyer:
    4. gain_profit = price * 0.2
    5. else:
    6. gain_profit = price * 0.1
    7. print(f'You will getting ${gain_profit}')
    # 12.逻辑运算符(and, or, not)优先级:not > and > or
    1. has_high_income = True
    2. has_good_credit = False
    3. has_criminal_record = False
    4. if (has_high_income or has_good_credit) and not has_criminal_record: # (T or F) and T
    5. print("允许贷款")
    6. else:
    7. print("不允许贷款")
    8. """
    9. 允许贷款
    10. """
    # 13. 比较运算符(>; >=; <; <=; !=; ==)
    1. temperature = int(input("请输入今天的气温:"))
    2. if temperature >= 30:
    3. print("今天是炎热的一天")
    4. elif 30 > temperature > 20:
    5. print("今天是温暖的一天")
    6. else:
    7. print("今天要加衣服了")
    8. """
    9. 请输入今天的气温:25
    10. 今天是温暖的一天
    11. """
    练习:你的名字长度必须不少于2个字符,且不能超过20个字符;
    符合规定的是好名字。
    1. name = input("请输入你的名字: ")
    2. if len(name) < 2:
    3. print("你的名字长度必须大于2个字符")
    4. elif len(name) > 20:
    5. print("你的名字长度必须小于20个字符")
    6. else:
    7. print("这是一个好名字")
    # 14.利用所学知识建立一个重量转换器小程序
    1. weight = int(input("weight: "))
    2. unit = input("(L)bs or (K)g: ")
    3. if unit.upper() == "L":
    4. converted = weight * 0.45
    5. print(f"You are {converted} kilos")
    6. elif unit.upper() == "K":
    7. converted = weight / 0.45
    8. print(f"You are {converted} pounds")
    9. else:
    10. print("Print error!")
    11. """
    12. weight: 120
    13. (L)bs or (K)g: l
    14. You are 54.0 kilos
    15. """

  • 相关阅读:
    Netty编码器和解码器
    多模态自编码器从EEG信号预测fNIRS静息态
    核密度的 bootstrap 置信区间
    SpringBoot采用Dynamic-Datasource方式实现多JDBC数据源
    SpikingJelly笔记之延迟编码
    【c++】刷题常用技巧
    著名书画家、中国书画院院士李适中
    A_Machine_Vision_Apparatus_and_Method_for_Can-End_Inspection-论文阅读笔记
    另一个博客
    LeetCode每日一题(1233. Remove Sub-Folders from the Filesystem)
  • 原文地址:https://blog.csdn.net/qq_57233919/article/details/132783723