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

  • 相关阅读:
    python 函数
    python升级功能
    python3与c++的不同点(初学看重点~)
    python中的数据结构
    github超简单用法
    ListView
    线性代数(1)--方程组的同解变形
    C++基础学习
    C++多态
    PKU《程序设计》专项课程_递归汉诺塔问题
  • 原文地址:https://www.cnblogs.com/bcaixl/p/11577615.html
Copyright © 2011-2022 走看看