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) + ...
随机推荐
- SQLServer 在Visual Studio的2种连接方法
一.Sql Server 在Visual Studio的连接有两种方法: (1)本地计算机连接; string s = "Data Source=计算机名称;initial Catalog= ...
- SQL 将一列多行数据合并为一行
原表数据: 期望结果: 使用STUFF + FOR XML PATH即可实现以上效果 执行以下SQL: , , '') AS Course FROM Student AS T 可以看到输出结果与期望结 ...
- odoo开发笔记--odoo可用小图标
odoo系统的小图标都采用了 fontawesome字体图标 官网: http://fontawesome.dashgame.com/ Github:http://fortawesome.github ...
- Centos 7 安装 Redis 3.2
环境: Centos 7 GCC #未安装,使用yum install gcc安装 1.下载redis 官方下载网站:https://redis.io/download.请在页面 ...
- Shell 流程控制 if while for
if else if if 语句语法格式: if condition then command1 command2 ... commandN fi 写成一行(适用于终端命令提示符): if [ $(p ...
- 计数排序/Counting Sort
计数排序的算法思想: 对于每一个元素x,只要确定了元素x有多少个比它小的元素,那么就可以知道其最终的位置. 记输入数组为A[n],存放最后排序输出的数组为B[n],提供临时存储空间的中间数组记为C[k ...
- windwos平台安装phpredis模块
要求 必备知识 熟悉基本编程环境搭建. 运行环境 windows 7(64位);php-5.3 redis64-2.8.17 下载地址 环境下载 什么是PHP Redis PHP Redis 是一个用 ...
- Docker环境的持续部署优化实践
最近两周优化了我们持续部署的程序,收效显著,记录下来分享给大家 背景介绍 那年公司快速成长,频繁上线新项目,每上线一个项目,就需要新申请一批机器,初始化,部署依赖的服务环境,一个脚本行天下 那年项目发 ...
- 轻量级web富文本框——wangEditor使用手册(5)——配置“插入代码”功能
最新版wangEditor: demo.文档:http://www.wangEditor.github.io/ 下载地址:https://github.com/wangfupeng1988/wangE ...
- springboot 多模块 -- 将web拆分出去 - 流动计算架构
前言: 之前将各层都拆分出去, 作为一个独立的可替换的子模块. 感觉比以前确实是灵活了一些. 不管是电商项目, 还是现在公司做的项目, 其中, 有很多的业务逻辑, 都是一样的, 但是由于不在一个系统中 ...