码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 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 ,体重转换器

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

    test2:简单比较运算符应用

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

  • 相关阅读:
    MySQL如何优雅处理批量新增和更新?ON DUPLICATE KEY UPDATE用它!
    读博后才知道的真道理
    全网唯一OpenCyphal/UAVCAN教程(8)libcanard介绍
    长时间久坐危害竟然这么大,这4项检查,男性朋友一定要定期查
    2022数模国赛C题思路解析(回顾,可供后面的比赛训练用)
    PyTorch训练RNN, GRU, LSTM:手写数字识别
    《WEB安全渗透测试》(31)BeEF-XSS一款红队XSS神器
    iOS 实现悬浮跟手滚动效果
    C++ "链链"不忘@必有回响之单链表
    未来软件测试行业职业选择有哪些?
  • 原文地址:https://blog.csdn.net/2201_75903640/article/details/140412898
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号