zoukankan      html  css  js  c++  java
  • 【Kata Daily 190924】Difference of Volumes of Cuboids(长方体的体积差)

    题目:

    In this simple exercise, you will create a program that will take two lists of integers, a and b. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids a and b. You must find the difference of the cuboids' volumes regardless of which is bigger.

    For example, if the parameters passed are ([2, 2, 3], [5, 4, 1]), the volume of a is 12 and the volume of b is 20. Therefore, the function should return 8.

    Your function will be tested with pre-made examples as well as random ones.

    If you can, try writing it in one line of code.

    解题办法:

    def find_difference(a, b):
        # Your code here!
        x = a[0]*a[1]*a[2]
        y = b[0]*b[1]*b[2]
        return max(x, y)-min(x, y)

    其他的办法:

    from numpy import prod
    
    def find_difference(a, b):
        return abs(prod(a) - prod(b))
    def find_difference(a, b):
      return abs((a[1]*a[2]*a[0])-b[1]*b[2]*b[0])

    知识点:

    1、绝对值使用abs()

    2、list里面值的乘积使用prod(list),需要导入,from numpy import prod

  • 相关阅读:
    zabbix验证微信
    free
    有名管道和无名管道
    shell实现并发控制
    TCP/IP协议簇 端口 三次握手 四次挥手 11种状态集
    自动化运维
    JSON对象(自定义对象)
    对象中属性的遍历、删除与成员方法
    对象间的赋值操作
    自定义类
  • 原文地址:https://www.cnblogs.com/bcaixl/p/11577615.html
Copyright © 2011-2022 走看看