题目:

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

【Kata Daily 190924】Difference of Volumes of Cuboids(长方体的体积差)的更多相关文章

  1. 【Kata Daily 190929】Password Hashes(密码哈希)

    题目: When you sign up for an account somewhere, some websites do not actually store your password in ...

  2. 【Kata Daily 191012】Find numbers which are divisible by given number

    题目: Complete the function which takes two arguments and returns all numbers which are divisible by t ...

  3. 【Kata Daily 191010】Grasshopper - Summation(加总)

    题目: Summation Write a program that finds the summation of every number from 1 to num. The number wil ...

  4. 【Kata Daily 190927】Counting sheep...(数绵羊)

    题目: Consider an array of sheep where some sheep may be missing from their place. We need a function ...

  5. 【Kata Daily 190923】Odder Than the Rest(找出奇数)

    题目: Create a method that takes an array/list as an input, and outputs the index at which the sole od ...

  6. 【Kata Daily 190920】Square(n) Sum(平方加总)

    题目: Complete the square sum function so that it squares each number passed into it and then sums the ...

  7. 【Kata Daily 190919】Sort Out The Men From Boys(排序)

    题目: Scenario Now that the competition gets tough it will Sort out the men from the boys . Men are th ...

  8. 【Kata Daily 190918】Spacify(插空)

    题目: Modify the spacify function so that it returns the given string with spaces insertedbetween each ...

  9. 【Kata Daily 190917】Numericals of a String(字符出现的次数)

    题目: You are given an input string. For each symbol in the string if it's the first character occuren ...

随机推荐

  1. 03 以Hello World为例,分析C语言的最小的程序结构

    C程序主要包含的部分 预处理器指令 函数 变量 语句 & 表达式 注释 C Hello World 实例 如下程序,可以在屏幕输出短句"Hello World" #incl ...

  2. notepad快捷使用

    1.快捷键 参考:https://www.php.cn/tool/notepad/428638.html notepad++是经常使用的一款编辑器软件,在编辑特殊文本的时候(html,java...) ...

  3. 脚手架安装react

    //1 npm install -g create-react-app //2 create-react-app xxx //xxx项目名称 //3 cd xxx //xxx项目名称 npm star ...

  4. 如何查找一个为NULL的MYSQL字段

    前言:在做这个题目 https://www.cnblogs.com/pipihao/p/13786304.html 因为之前 我好像没有接触过什么 为NULL字段的查询,细节不小 WHERE 字段 I ...

  5. JVM 第三篇:Java 类加载机制

    本文内容过于硬核,建议有 Java 相关经验人士阅读. 1. 什么是类的加载? 类的加载指的是将类的 .class 文件中的二进制数据读入到内存中,将其放在运行时数据区的方法区内,然后在堆区创建一个 ...

  6. 实验六 DIV+CSS的综合应用

    实验六 DIV+CSS的综合应用 [实验目的] 1.掌握DIV布局的方法: 2.利用CSS对DIV进行美化: 3.利用CSS对文本图像等网页元素进行美化 [实验环境] 连接互联网的PC ,Win7操作 ...

  7. 多测师讲解自动化测试 _RF定位iframe框_高级讲师肖sir

    Open Browser https://mail.163.com/ gc Maximize Browser Window sleep 2 #进入if框 Comment Input Text name ...

  8. 【自学编程】C语言编程简单的小程序,计算长方体体积!

    计算长方体体积 有朋友会说长方体体积还不好算吗?长X宽X高.没错用计算器一下就可以出结果,编程反而麻烦些,但是我们说的是这种思维,如果复杂的重复运算的话写好程序就非常简单了. 简单运算下一个固定高度的 ...

  9. vagrantfile-参考示例

    Vagrantfile 文件  bt为你需要新建的box名字    Vagrant.configure("2") do |config|   config.vm.box = &qu ...

  10. JavaSE学习笔记01注释、标识符与基本类型

    1. HelloWorld 编写代码 public class Hello{ public static void main(String[] args){ System.out.println(&q ...