博客
关于我
7-3 jmu-python-判断是否构成三角形
阅读量:521 次
发布时间:2019-03-07

本文共 374 字,大约阅读时间需要 1 分钟。

对于给定的三个整数边长,判断是否能构成三角形:

首先,三角形的任意两边之和必须大于第三边。这意味着对于三条边a、b、c,必须满足以下三个条件:

  • a + b > c
  • a + c > b
  • b + c > a
  • 如果满足上述三个条件,则可以构成三角形;否则,不可以。

    接下来,我会按照以下步骤解决这个问题:

  • 读取三个整数输入。
  • 判断这三个条件是否同时满足。
  • 输出yes或no的结果。
  • 代码如下:

    a, b, c = map(int, input().split())if a + b > c and a + c > b and b + c > a:    print("yes")else:    print("no")

    这个方法不仅判断了各边是否符合三角形条件,而且也处理了边长为负数或零的情况,确保输入的正确性。同时,这样的判断逻辑简洁明了,易于理解。

    转载地址:http://fqfnz.baihongyu.com/

    你可能感兴趣的文章
    NMAP网络扫描工具的安装与使用
    查看>>
    NMF(非负矩阵分解)
    查看>>
    nmon_x86_64_centos7工具如何使用
    查看>>
    NN&DL4.1 Deep L-layer neural network简介
    查看>>
    NN&DL4.3 Getting your matrix dimensions right
    查看>>
    NN&DL4.7 Parameters vs Hyperparameters
    查看>>
    NN&DL4.8 What does this have to do with the brain?
    查看>>
    nnU-Net 终极指南
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    NO 157 去掉禅道访问地址中的zentao
    查看>>
    no available service ‘default‘ found, please make sure registry config corre seata
    查看>>
    No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
    查看>>
    no connection could be made because the target machine actively refused it.问题解决
    查看>>
    No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
    查看>>
    No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
    查看>>
    No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
    查看>>
    No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
    查看>>
    No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
    查看>>
    No module named 'crispy_forms'等使用pycharm开发
    查看>>