Hey everybody, this is my first post, so I hope I'm doing this right. I'm just starting to learn how to program, so I'm sorry if my error is obvious, but I can't seem to find the answer.
I created a very simple while loop in a test program that determines your dating range with a simple calculation, and then asks if you want to try again with a question, and will repeat until you decline.I t works perfectly. I tried doing the same thing in a very simple program that basically just calculates compound interest, but the while loop doesn't seem to work the same, despite being almost identical to my "dating age" program.
Here is the output/error message when I use the compound interest program:
Here is the code to my "dating age" program, which works fine:
Here is the code for my compound interest program, which won't seem to work:
I also realize that there are obvious other problems with my compound interest program, such as not rounding decimals, but I'm just using this to learn, so I'm tackling one thing at a time.
Thank you very much in advance for any help!
I created a very simple while loop in a test program that determines your dating range with a simple calculation, and then asks if you want to try again with a question, and will repeat until you decline.I t works perfectly. I tried doing the same thing in a very simple program that basically just calculates compound interest, but the while loop doesn't seem to work the same, despite being almost identical to my "dating age" program.
Here is the output/error message when I use the compound interest program:
Code:
Hello.
Would you like to try? Please enter yes or no: yes
How old are you? 19
Please enter cash value: 10000
Please enter interest rate in the form of a decimal: .1
What age would you like to check your worth? 35
Here is your worth: 45949.7298636
Here is your profit: 35949.7298636
Would you like to try again? yes
Traceback (most recent call last):
File "/Users/johnhutchison/Documents/worth.py", line 4, in <module>
while decision in y:
TypeError: argument of type 'int' is not iterable
logout
[Process completed]
Code:
print "Welcome! Let's see who you can date!"
y = [ 'yes', 'y', 'Yes', 'Y' ]
decision = raw_input("Would you like to try? Please enter yes or no: ")
while decision in y:
age = input("Please enter age: ")
age_min = age / 2 + 7
age_max = (age - 7) * 2
print "Your dating range is between:", age_min, "and", age_max
decision = raw_input("Would you like to try again? Please enter y or n: ")
raw_input("Thank you! Press Enter to exit.")
Code:
print "Hello."
y = [ 'yes', 'y', 'Yes', 'Y' ]
decision = raw_input("Would you like to try? Please enter yes or no: ")
while decision in y:
age = input("How old are you? ")
p = input("Please enter cash value: ")
i = input("Please enter interest rate in the form of a decimal: ")
y = input("What age would you like to check your worth? ") - age
cash_worth = p * (1 + i)**y
profit = cash_worth - p
print "Here is your worth:", cash_worth
print "Here is your profit:", profit
decision = raw_input("Would you like to try again? ")
raw_input("Press Enter to leave")
Thank you very much in advance for any help!
Comment