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) + ...
随机推荐
- 说一下acad的bug及问题
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk. ...
- mongoose入门
概述 像Mysql和Mongodb这样的数据库,一般都是在命令行或者工具里面进行操作,如果想在node搭建的服务器上面操作,就必须要利用特殊的模块的.其中操作Mongodb数据库需要用到mongoos ...
- SQL 一对多联表查询最大值
有两个数据表City表和Price表,CIty表的结构如下: Price表的结构如下: 查询每个城市最大的销售价格,并以最大价格进行降序排列,选取前5条记录,SQL语句的代码如下: * from (s ...
- String s=“dd”和String s=new String("dd")区别
Java中String s="dd"的话会先检查常量池中是否有"dd"这个字符串,如果没有则创建一个,然后将s指向字符串的地址,而new String(&quo ...
- golang 切片和数组在for...range中的区别
切片是引用类型,而数组是值类型,并且for...range有以下规则: range表达式只会在for语句开始执行时被求值一次,无论后边会有多少次迭代 range表达式的求值结果会被复制,也就是说,被迭 ...
- static、final、static final的区别
final: final可以修饰属性,方法,类,局部变量(方法中的变量) final修饰的属性的初始化可以在编译期,也可以在运行期,初始化后不能被改变. final修饰的属性跟具体对象有关,在运行期初 ...
- 如何开启windows的linux子系统
win10一周年纪念版 1607的版本增加了bash,bash,bash,windows的shell中可以直接运行bash了. 下面说一下配置步骤: 1.设置 —更新和安全—针对开发人员,选择开发人 ...
- Python相关在线文档手册地址
Python相关: 五星推荐:http://python.usyiyi.cn/ Python 2.7官方中文文档:http://doc.iplaypy.com/python2/ 英文: htt ...
- 阿里巴巴Java开发规范---个人总结
一.编程规约 (一) 命名规约 1. [强制]所有编程相关命名均不能以下划线或美元符号开始,也不能以下划线或美元符号结束. 反例: _name / __name / $Object / name_ / ...
- Storm中的定时任务
1.全局定时器 import java.util.Map; import backtype.storm.Config; import backtype.storm.Constants; import ...