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:
Expand|Select|Wrap|Line Numbers
- 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]
Expand|Select|Wrap|Line Numbers
- 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.")
Expand|Select|Wrap|Line Numbers
- 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!