Python:逻辑运算符and比较运算符以及布尔输入

# bool输入 将空字符串作为False 
is_hot = bool(input("t or f"))

运算符

# 逻辑运算符
# &&  and
# ||  or
# !   not 但是要表达多个之间,需要用上面的两个词作为连接词
has_high_income = False
has_good_credit = True
if has_good_credit or has_high_income:
    print("get a little loan ")
if has_good_credit and has_high_income:
    print("get loan")
else:
    print("not get loan")
if has_good_credit and not has_high_income:
    print("say no")
if not has_high_income:
    print("so poverty")


# 比较运算符 >=    <=     >   <    ==   !=
temperature = 30
if temperature == 30:
    print("It's hot day")
else:
    print("It's not hot day")

test 1 ,体重转换器

# 输入kg转换为bs bs转换kg
user_weight = input("Weight : ")
option = input("(L)bs or (K)g: ")
# if option == 'L' or option == 'l':
if option.upper()=='L':
    print(f"you are {float(user_weight) * 0.45} kg")
elif option.upper() == 'K':
    print(f"you are {float(user_weight) / 0.45} pounds")
else:
    print("your option had error! ")
# index的正负应用
name = "Jennifer"
print(name[1:-1])

test2:简单比较运算符应用

name = input("What's your name? ")
length = len(name)
if length < 3:
    print("the name must be at least 3 characters")
elif length > 50:
    print("the name can be a maximum of 50 characters")
else:
    print(f'name: {name} looks good!')

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-14 11:22:03       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-14 11:22:03       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-14 11:22:03       45 阅读
  4. Python语言-面向对象

    2024-07-14 11:22:03       55 阅读

热门阅读

  1. C++ STL stable_sort用法

    2024-07-14 11:22:03       19 阅读
  2. Nikto 扫描 Web 服务器漏洞

    2024-07-14 11:22:03       22 阅读
  3. 优化实战篇—自关联的优化

    2024-07-14 11:22:03       16 阅读
  4. todolist-原生js(ES6)

    2024-07-14 11:22:03       19 阅读
  5. 日常学习--docker命令梳理--20240714

    2024-07-14 11:22:03       22 阅读
  6. iOS热门面试题(四)

    2024-07-14 11:22:03       23 阅读
  7. 56. 合并区间

    2024-07-14 11:22:03       20 阅读
  8. 微服务架构,通信协议,Web服务器和kafka

    2024-07-14 11:22:03       17 阅读
  9. 【学习笔记】Redis学习笔记——第9章 数据库

    2024-07-14 11:22:03       21 阅读
  10. 基于gunicorn+flask+docker模型高并发部署

    2024-07-14 11:22:03       20 阅读
  11. 求助大佬——期末考试评分标准(浙大)C语言

    2024-07-14 11:22:03       23 阅读
  12. 如何解决数据分析问题:IPython与Pandas结合

    2024-07-14 11:22:03       14 阅读
  13. 【团队成长】2024-28周周报

    2024-07-14 11:22:03       21 阅读