博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Code Signal_练习题_depositProfit
阅读量:6948 次
发布时间:2019-06-27

本文共 980 字,大约阅读时间需要 3 分钟。

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 = 100rate = 20, and threshold = 170, the output should be

depositProfit(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
膜拜大佬

 

转载于:https://www.cnblogs.com/BlameKidd/p/9476135.html

你可能感兴趣的文章
Mysql 临时表的创建和删除
查看>>
db file scattered read等待事件
查看>>
ArcGIS Engine 中的多线程使用 (转载)
查看>>
linux下c的网络编程---转载
查看>>
filter中的DelegatingFilterProxy使用事例
查看>>
WinForm 天猫2013双11自动抢红包【源码下载】
查看>>
学习数学从《数学之美》开始
查看>>
flashcache的实现与分析
查看>>
[UML]UML系列——状态机图statechart diagram
查看>>
微信公众平台开发(74) 用户分组管理
查看>>
二、jdk命令之javah命令(C Header and Stub File Generator)
查看>>
ios模拟器未能安装此应用程序
查看>>
站长常用的200个js代码 站长常用js代码大全 站长常用js代码集合
查看>>
HBase eclipse开发环境搭建
查看>>
SQL Server - 把星期一(周一)当作每个星期的开始在一年中求取周数
查看>>
【ASP.NET Web API教程】6.2 ASP.NET Web API中的JSON和XML序列化
查看>>
jquery-alert对话框
查看>>
WIN8系统安装软件时提示"扩展属性不一致"的解决方法
查看>>
sqlite3.exe 使用
查看>>
微软职位内部推荐-Senior Software Engineer
查看>>