【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
【Kata Daily 190924】Difference of Volumes of Cuboids(长方体的体积差)的更多相关文章
- 【Kata Daily 190929】Password Hashes(密码哈希)
题目: When you sign up for an account somewhere, some websites do not actually store your password in ...
- 【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 ...
- 【Kata Daily 191010】Grasshopper - Summation(加总)
题目: Summation Write a program that finds the summation of every number from 1 to num. The number wil ...
- 【Kata Daily 190927】Counting sheep...(数绵羊)
题目: Consider an array of sheep where some sheep may be missing from their place. We need a function ...
- 【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 ...
- 【Kata Daily 190920】Square(n) Sum(平方加总)
题目: Complete the square sum function so that it squares each number passed into it and then sums the ...
- 【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 ...
- 【Kata Daily 190918】Spacify(插空)
题目: Modify the spacify function so that it returns the given string with spaces insertedbetween each ...
- 【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 ...
随机推荐
- 学习git这一篇就够了!!!
git命令操作 本地库操作 初始化本地仓库 初始化命令 git init $ work % cd workspace $ workspace % mkdir WebService //创建文件夹 $ ...
- set的运用 例题5-3 安迪的第一个字典(Andy's First Dictionary,Uva 10815)
#include<bits/stdc++.h>using namespace std;set<string> dict;int main(){ string s, buf; w ...
- Jmeter之参数化函数助手__CSVRead
1.在Tool->函数对话框中选择__CSVRead,2处填写测试用例的文档地址(测试用例要以csv格式保存),3处是测试用例中参数的位置,第一栏参数的CSV文件列号填0,第二栏参数的CSV文件 ...
- Python虚拟环境操作
1.安装pip install virtualenvwrapperpip install virtualenvwrapper-win #Windows使用该命令 2.创建一个文件夹,用来保存虚拟环境目 ...
- SQL SERVER调优常用方法 sql优化
说起SQL SERVER的调优,我想大伙也很想知道这方面的知识.本人也正在探索的路上,大家有什么好的意见,欢迎一起探讨.研究.博取众人之长,才能扬长避短.本文中的内容主要是摘自<程序员的SQL金 ...
- 探索ParNew和CMS垃圾回收器
前言 上篇文章我们一起分析了JVM的垃圾回收机制,了解了新生代的内存模型,老年代的空间分配担保原则,并简单的介绍了几种垃圾回收器.详细内容小伙伴们可以去看一下我的上篇文章:秒懂JVM的垃圾回收机制. ...
- Markdown基础知识
一 Markdown简介 Markdown是⼀种可以使⽤普通⽂本编辑器编写的标记语⾔,通过简单的标记语法,它可以使普通⽂本内容具有⼀定的格式,可以简单理解为纯⽂本格式的word. 软件⼀般⽤vscod ...
- Java接口的初始化
背景 接口与类真正有所区别的是前面讲述的四种"有且仅有"需要开始初始化场景中的第三种:当一个类在初始化时,要求其父类全部都已经初始化过了,但是一个接口在初始化时,并不要求其父接口全 ...
- node初学
安装node.js 往往需要解析环境,但是现在直接安装时就已经配置好了, cmd打开 输入cd/ 在输入node -v 显示版本号 Node与php比较:https://www.techug.co ...
- git学习(十) idea git reset 操作
git reset 是回滚操作,在 idea 中使用如下: Reset Type 有三种: Mixed 默认方式,只保留源码,回退 commit 和 index 信息 Soft 回退到某个版本,只回退 ...