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

膜拜大佬

Code Signal_练习题_depositProfit的更多相关文章

  1. Code Signal_练习题_digitDegree

    Let's define digit degree of some positive integer as the number of times we need to replace this nu ...

  2. Code Signal_练习题_Knapsack Light

    You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...

  3. Code Signal_练习题_growingPlant

    Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...

  4. Code Signal_练习题_arrayMaxConsecutiveSum

    Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...

  5. Code Signal_练习题_differentSymbolsNaive

    Given a string, find the number of different characters in it. Example For s = "cabca", th ...

  6. Code Signal_练习题_firstDigit

    Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...

  7. Code Signal_练习题_extractEachKth

    Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...

  8. Code Signal_练习题_stringsRearrangement

    Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...

  9. 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) + ...

随机推荐

  1. C# MemoryStream BinaryReader

    不清楚这类东西内部搞什么鬼,直接看代码才舒爽 https://referencesource.microsoft.com/#mscorlib 然后可以在线测试 https://www.tutorial ...

  2. pika配置文件说明

    # Pika 端口 port : 9221 # pika进程数量,不建议超过核心数量,pika是多线程的 thread-num : 1 # Sync 线程数量 sync-thread-num : 6 ...

  3. GoLang学习控制语句之switch

    基本结构 相比较 C 和 Java 等其它语言而言,Go 语言中的 switch 结构使用上更加灵活.它接受任意形式的表达式,例如: switch var1 { case val1: ... case ...

  4. 【UML】:时序图

    时序图表达了类之间调用关系,以及调用时序关系. Actor: 调用者实例化类的对象,执行者. Lifeline: 生命线,竖的虚线.上方方框是类名表示存在的时间,从上至下表示时间流逝.Lifeline ...

  5. sublime text3:提示 There are no packages available installation 解决方案

    纯属记录,下次能找到解决. 第一步: 在sublime Text3界面按 ctrl+` 出现一个输入框界面 第二步:在输入框输入: import urllib.request,os,hashlib; ...

  6. Redis 入门知识

    Redis 的前世今生 Redis的诞生于2008年,由Salvatore Sanfilippo开发.最初作者在开发一个网站时,需要实现一个高性能的队列功能,在使用Mysql无果后,决定自己造一个轮子 ...

  7. [LeetCode] 反转整数

    题目: 给定一个 32 位有符号整数,将整数中的数字进行反转. 示例 1: 输入: 123 输出: 321 示例 2: 输入: -123 输出: -321 示例 3: 输入: 120 输出: 21 注 ...

  8. 阿里巴巴Java开发规范---个人总结

    一.编程规约 (一) 命名规约 1. [强制]所有编程相关命名均不能以下划线或美元符号开始,也不能以下划线或美元符号结束. 反例: _name / __name / $Object / name_ / ...

  9. VScode中支持Python虚拟环境

    要在VScode中使用Python的virtualenv虚拟环境,首先在设置同添加虚拟环境所在目录和虚拟环境的识别规则: { ... "python.venvPath": &quo ...

  10. (转)python之from_bytes、to_bytes

    原文:https://blog.csdn.net/PYTandFA/article/details/78741339 https://python3-cookbook.readthedocs.io/z ...