0

## Python 迴圈練習

Statement
As a future athlete you just started your practice for an upcoming event. Given that on the first day you run x miles, and by the event you must be able to run y miles.
Calculate the number of days required for you to finally reach the required distance for the event, if you increases your distance each day by 10% from the previous day.

Print one integer representing the number of days to reach the required distance.

``````a = int(input()) --第一天可以跑得miles
b = int(input()) --最後一天目標miles
ans = 0 --紀錄每一天可以跑得miles
i = 1 --從第一天開始
while ans <= b:
ans = a * 1.1
i += 1
print(i) --印出總共訓練了幾天
``````

snakify練習網址

(PS 需要註冊後才可以練習題目)

``````a = int(input())
b = int(input())
ans = 0
i =  1
if(a < b):
while ans < b:
ans = a * 1.1
i += 1
a = ans
print(i)
``````

``````a = int(input())
b = int(input())
i =  1
if(a < b):
while a < b:
a *= 1.1
i += 1
print(i)
``````

froce iT邦大師 1 級 ‧ 2020-02-20 10:57:19 檢舉

a = ans

Zed_Yang iT邦新手 3 級 ‧ 2020-02-20 11:31:21 檢舉

while a <b:
a+= a*0.1
i+=1

Zed_Yang iT邦新手 3 級 ‧ 2020-02-20 11:47:11 檢舉

while a <b:
a *= 1.1
i+=1

a *= 1.1 等於 a = a*1.1

limit 設個一萬十萬都可以，看跑多複雜的內容自己評估一下，反正要有停下來的條件 ..
Zed_Yang iT邦新手 3 級 ‧ 2020-02-21 13:37:52 檢舉

### 1 個回答

2
mlck970677
iT邦新手 5 級 ‧ 2020-02-20 10:57:12

``````ans = a * 1.1
``````

nezuko ~<3