Code Signal_练习题_depositProfit
You have deposited a specific amount of money into your bank account. Each year your balance increases at the same growth rate. With the assumption that you don't make any additional deposits, find out how long it would take for your balance to pass a specific threshold. Of course you don't want to wait too long, so you know that the answer is not greater than 6.
Example
For deposit = 100, rate = 20, and threshold = 170, the output should bedepositProfit(deposit, rate, threshold) = 3.
Each year the amount of money in your account increases by 20%. So throughout the years, your balance would be:
- year 0:
100; - year 1:
120; - year 2:
144; - year 3:
172.8.
Thus, it will take 3 years for your balance to pass the threshold, so the answer is 3.
我的解答:
def depositProfit(deposit, rate, threshold):
count = 0
while deposit < threshold:
deposit += deposit * rate * 0.01
count += 1
return count
写的一样...0.0
膜拜大佬
Code Signal_练习题_depositProfit的更多相关文章
- Code Signal_练习题_digitDegree
Let's define digit degree of some positive integer as the number of times we need to replace this nu ...
- Code Signal_练习题_Knapsack Light
You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...
- Code Signal_练习题_growingPlant
Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...
- Code Signal_练习题_arrayMaxConsecutiveSum
Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...
- Code Signal_练习题_differentSymbolsNaive
Given a string, find the number of different characters in it. Example For s = "cabca", th ...
- Code Signal_练习题_firstDigit
Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...
- Code Signal_练习题_extractEachKth
Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...
- Code Signal_练习题_stringsRearrangement
Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...
- Code Signal_练习题_absoluteValuesSumMinimization
Given a sorted array of integers a, find an integer x from a such that the value of abs(a[0] - x) + ...
随机推荐
- PICE(2):JDBCStreaming - gRPC-JDBC Service
在一个akka-cluster环境里,从数据调用的角度上,JDBC数据库与集群中其它节点是脱离的.这是因为JDBC数据库不是分布式的,不具备节点位置透明化特性.所以,JDBC数据库服务器必须通过服务方 ...
- 微信小程序之模版的使用(template)
WXML提供模板(template),可以在模板中定义代码片段,然后在不同的地方调用. 分为两部分,定义模板和使用模板 (1).定义模板:使用 name 属性,作为模板的名字.然后在<templ ...
- UI的设计,适配器,以及RecyclerView无法加载的解决办法
这本书里讲到的界面设计都是用最基本的方式实现的,即编写xml文件 所有的控件都具有宽度和高度属性,即android:layout_width和android:layout_height,这两个属性对应 ...
- Metasploit数据库问题汇总
数据库在metaspoit中是相当重要的,当做一个大型渗透测试项目的时候,收集到的信息是相当大的,当和你的同伴一起协同作战的时候,你们可能 在不同的地方,所以数据共享很重要了!而且Metasploit ...
- IE中透明度的读写
一.获取透明度 ele.filters.alpha 返回元素所有滤镜的对象,可在此基础上获取opacity即可. 但是似乎ele.filters只能存储第一个滤镜,而当我们把alpha放在第二位时,就 ...
- php -- 数学函数
----- 016-math.php ----- <!DOCTYPE html> <html> <head> <meta http-equiv="c ...
- spring security的简单应用
本文只包涵spring security配置部分,不是一个完整项目,不过可以任意添加到一个web项目中,不需要对原来的程序做任何修改 部分内容来源于网络,如有雷同,毫无意外 1.xml配置文件 < ...
- SpringCloud入门之Maven系统安装及配置
一.Maven 介绍 这个单词中文翻译为“专家”或“内行”.下面将向你介绍 Maven这一跨平台的项目管理工具.作为 Apache 组织中的一个成功的开源项目,Maven 主要服务于基 Java 平台 ...
- php里use关键字与class_alias的作用域区别
use可以用在命名空间下,也可以不用再命名空间下,他在两者中的作用是一致的,都是在编译的时候执行,不真正的加载类,因为是编译的时候执行,所以只能在全局环境使用,及不能使用在方法内部,条件判断内部. 引 ...
- mysql 获取自增主键
MyBatis 3.2.6插入时候获取自增主键方法有二 以MySQL5.5为例: 方法1: <insert id="insert" parameterType="P ...