题目:

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. Camera光学、成像和 3A 算法 (视觉),camera开发

    简单介绍 转载:https://blog.csdn.net/ShareUs/article/details/94295628 成像与光学.计算机视觉,图像处理,数字成像.自动驾驶与视觉. 镜头设计:人 ...

  2. 如何选择JVM垃圾回收器?

    明确垃圾回收器组合 -XX:+UseSerialGC 年轻代和老年代都用串行收集器 -XX:+UseParNewGC 年轻代使用ParNew,老年代使用 Serial Old -XX:+UsePara ...

  3. K8S-ETCD数据库备份与恢复

    kubernetes使用etcd数据库实时存储集群中的数据,安全起见,一定要备份 需要指定使用etcdctl的版本 etcd数据库备份是使用数控快照的方式进行备份的,备份后的新数据不会保留,后面创建的 ...

  4. SCOI 2008 【奖励关】

    早上的考试一道都做不出,被教做人,心态爆炸ing...... 题目描述: 你正在玩你最喜欢的电子游戏,并且刚刚进入一个奖励关.在这个奖励关里,系统将依次随机抛出k次宝物,每次你都可以选择吃或者不吃(必 ...

  5. 解决VMware无法共享ubuntu虚拟机文件

    1.错误信息:无法更新运行时文件夹共享状态:在客户机操作系统内装载共享文件夹文件系统时出错 2.检查vmware tool是否正确安装 lsmod | grep vmhgfs modprobe vmh ...

  6. day27 Pyhton 面向对象02 类和对象的命名空间

    一.内容回顾 类:具有相同属性和方法的一类事务 # 描述一类事务轮廓的一个机制 #商品/用户/店铺 对象/实例: 对象(实例)就是类的实例化 # 对象就是类的一个具体的表现 #某一件特定的商品/某个人 ...

  7. RHEL8和CentOS8怎么重启网络

      本文主要讲解如何重启RHEL 8或者CentOS 8网络以及如何解决RHEL8和CentOS8系统的网络管理服务报错,当我们安装好RHEL 8或者 CentOS 8,重启启动网络时,会出现以下报错 ...

  8. docker19.03限制容器使用的内存资源

    一,指定内存大小的参数: [root@localhost liuhongdi]# docker run -idt --name kafka2 --hostname kafka2 -m 200M --m ...

  9. 第三十三章 linux常规练习题(二)

    一.练习题一 1.删除用户基本组shanghai03.发现无法正常删除,怎样才能将其删除掉,不能删除用户.2.打开多个xshell窗口连接登录同一虚拟机,使用不同的用户登录多次,分别使用w和who命令 ...

  10. 企业级RPC框架zRPC

    近期比较火的开源项目go-zero是一个集成了各种工程实践的包含了Web和RPC协议的功能完善的微服务框架,今天我们就一起来分析一下其中的RPC部分zRPC. zRPC底层依赖gRPC,内置了服务注册 ...