0

How to write a "while" or "for" loop with limit based on whatever user input is received

"Design a program that calculates the amount of money a person would earn over a period of time, which doubles every day(aka day1=.01 cents, day2=.02 cents, day3=.04 cents etc). Program should ask the user for the number of days" I am not sure how to begin to write a script that works around user input?

20th Feb 2017, 10:04 PM
auri
auri - avatar
5 Respuestas
+ 1
Copy and paste to an online IDLE. Not the SoloLearn one.
20th Feb 2017, 10:25 PM
DerpyOmnister
DerpyOmnister - avatar
0
Money = input("Type in your money today: ") Days = input("Type How many days: ") Earned = True while Earned == True: i = 1 while i <= Days: print("Day " + str(i) + " = " + str(Money)) Money *= 2 i += 1 if i > Days: Earned = False break
20th Feb 2017, 10:23 PM
DerpyOmnister
DerpyOmnister - avatar
0
I haven't been taught true or false statements yet! Only on chapter 5! But thank you, This at least confirmed that a while statement is necessary! Thanks Auri
20th Feb 2017, 10:30 PM
auri
auri - avatar
0
The input should be the number of days, something like this: # ask the user for input, then convert the input to integer days = int(input("enter the number of days: ")) # loop for i in range(days): do something This loop only iterates the number of days the user input. In other words, while i < days, keep looping.
20th Feb 2017, 11:04 PM
Fernando
0
@DerpyOmnister: your code is broken, Money is already a str and you can't order str and int (Days is a str).
21st Feb 2017, 2:02 PM
Amaras A
Amaras A - avatar