473,394 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

I'm having trouble with a very simple while loop in 1 program, but not another.

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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Hello.
  3. Would you like to try? Please enter yes or no: yes
  4. How old are you? 19
  5. Please enter cash value: 10000
  6. Please enter interest rate in the form of a decimal: .1
  7. What age would you like to check your worth? 35
  8. Here is your worth: 45949.7298636
  9. Here is your profit: 35949.7298636
  10. Would you like to try again? yes
  11. Traceback (most recent call last):
  12.   File "/Users/johnhutchison/Documents/worth.py", line 4, in <module>
  13.     while decision in y:    
  14. TypeError: argument of type 'int' is not iterable
  15. logout
  16.  
  17. [Process completed]
  18.  
Here is the code to my "dating age" program, which works fine:

Expand|Select|Wrap|Line Numbers
  1. print "Welcome! Let's see who you can date!"
  2. y = [ 'yes', 'y', 'Yes', 'Y' ]
  3. decision = raw_input("Would you like to try? Please enter yes or no: ")
  4. while decision in y:
  5.     age = input("Please enter age: ")
  6.     age_min = age / 2 + 7 
  7.     age_max = (age - 7) * 2
  8.     print "Your dating range is between:", age_min, "and", age_max    
  9.     decision = raw_input("Would you like to try again? Please enter y or n: ")            
  10. raw_input("Thank you! Press Enter to exit.")
  11.  
Here is the code for my compound interest program, which won't seem to work:

Expand|Select|Wrap|Line Numbers
  1. print "Hello."
  2. y = [ 'yes', 'y', 'Yes', 'Y' ]
  3. decision = raw_input("Would you like to try? Please enter yes or no: ")
  4. while decision in y:    
  5.     age = input("How old are you? ")
  6.     p = input("Please enter cash value: ")
  7.     i = input("Please enter interest rate in the form of a decimal: ")
  8.     y = input("What age would you like to check your worth? ") - age
  9.     cash_worth = p * (1 + i)**y
  10.     profit = cash_worth - p
  11.     print "Here is your worth:", cash_worth
  12.     print "Here is your profit:", profit
  13.     decision = raw_input("Would you like to try again? ")
  14. raw_input("Press Enter to leave")
  15.  
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!
Nov 7 '10 #1

✓ answered by dwblas

The problem is that you are using single letter variable names and so an IDE or text processor can not find all instances of a variable. It can only find every time that letter was used any where. So
while decision in y:
TypeError: argument of type 'int' is not iterable
says that you set "y" to an integer value somewhere in the code, which is true, but I am going to leave it to you to find that particular "y" as a lesson in why we should use descriptive variable names.

2 3385
dwblas
626 Expert 512MB
The problem is that you are using single letter variable names and so an IDE or text processor can not find all instances of a variable. It can only find every time that letter was used any where. So
while decision in y:
TypeError: argument of type 'int' is not iterable
says that you set "y" to an integer value somewhere in the code, which is true, but I am going to leave it to you to find that particular "y" as a lesson in why we should use descriptive variable names.
Nov 7 '10 #2
Oh, I totally see my mistake! I assigned "y" twice. I feel like an idiot. I'll definitely be sure to start naming variables more descriptively. Thank you very much for your help and patience!
Nov 7 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i...
2
by: Jozef | last post by:
Hello, I am trying to put together a module and open a workspace on a database that has a simple password (using Access XP). This is the lin that I'm having trouble with; Set wrk =...
8
by: SK | last post by:
Hi I am trying to write a simple C program with devc++ as the complier using the concept of arrays. I cannot get the program to compile without mutiple errors. If anyone has the time to help me...
5
by: tkondal | last post by:
Hi all. I just started looking at Python's ctypes lib and I am having trouble using it for a function. For starters, here's my Python code: from ctypes import*; myStringDLL=...
2
by: spidey12345 | last post by:
what i need this program to do is to read paragraphs like "st blah blh test ere se sit blha eere w" and then it will reformat to "st blah...
2
by: QHorizon | last post by:
Hello, I'm new to Python (I've learned everything up to iterators so far) and fairly new to Programming. This would be my first real program: #Coordinate Geometry (The whole program is not...
23
by: AndersWang | last post by:
Hi, dose anybody here explain to me why memset would be faster than a simple loop. I doubt about it! In an int array scenario: int array; for(int i=0;i<10;i++) //ten loops
1
by: ced69 | last post by:
having trouble getting marquee to work get object required errors tring t <title>This Month at the Chamberlain Civic Center</title> <link href="styles.css" rel="stylesheet"...
1
by: jerry | last post by:
i have written a simple phonebook program,i'll show you some of the codes,the program's head file is member.h . i suppose the head file works well.so i don't post it. here's the clips of main...
1
by: runningsnake24 | last post by:
We are writing a program to check that a filled in Sudoku puzzle is solved correctly. We are required to use the Iterator and Iterable interfaces. The program uses a Cell class to represent each...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.