题目:

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. 使用SignalR和XSLT进行实时注释

    下载source code - 10.1 MB Introduction  众所周知,web请求(HTTP请求)是根据请求/响应机制工作的.通过这种方式,作为客户机的浏览器使用GET或POST向服务器 ...

  2. Centos 6.9安装 php5.6 过程中报错:Error: Package: php56w-mcrypt-5.6.40-1.w6.x86_64 (webtatic)

    在 CentOS 6.9 系统下安装 php 5.6 的过程中,执行如下命令: yum -y install php56w-pdo php56w-xml php56w-gd php56w-gd.x86 ...

  3. Prometheus第一篇:Prometheus架构解析

    Prometheus是新一代的监控系统解决方案,原生支持云环境,和kubernetes无缝对接,的却是容器化监控解决方案的不二之选.当然对传统的监控方案也能够兼容,通过自定义或是用开源社区提供的各种e ...

  4. 架构师根本不会被语言限制住,php照样可以用领域驱动设计DDD四层架构!

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 你在通往架构师的路上吗? 程序员这个行业就像是在不断的打怪升级,突破每一阶段的瓶颈期 ...

  5. dubbo使用问题

    新入职此公司, 发现公司使用的框架原来是传说中的分布式的(原谅我以前在传统公司工作,并远离浪潮久矣), 使用过程中发现各服务之间使用 dubbo 进行通信. 特地总结下遇见的坑,为以后总结经验.   ...

  6. 高效的后端API开发模板-illuminant

    概要 整体介绍 补充说明 Q. 有了 prisma 自动生成的 graphql 接口, 为什么还要 rest 接口和 websocket 接口? Q. 为什么要通过 illuminant 加一层反向代 ...

  7. 多测师讲解python __for 循环___高级讲师肖sir

    横向输出 1.遍历字符串 2.遍历列表 3.遍历元组 方法一: 方法二: 方法三: #循环字典:方法一# dict1={"name":"zhihao",&quo ...

  8. 【树形DP】ZJOI2008 骑士

    题目内容 洛谷链接 有\(n\)位骑士,每个人的战力可能不同,并且每一个人都有且仅有一个憎恨的人,互相憎恨的人不能在同一队中. 求组合为一个骑士队的最大战斗力. PS:可以去看看题目背景学学历史(雾) ...

  9. 国内首个 .NET 5 框架 Fur 斩获 1000 stars,1.0.0-rc.final.20 发布

          Fur 是 .NET 5 平台下企业应用开发最佳实践框架. 通往牛逼的路上,风景差得让人只想说脏话,但我在意的是远方. 啥环境 早在 1998 年微软公司对外发布 .NET/C# 平台的那 ...

  10. Django折腾日记(django2.0)

    新建项目 django-admin startproject mysite 运行 python manage.py runserver 创建一个应用 python manage.py startapp ...