By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,097 Members | 1,580 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,097 IT Pros & Developers. It's quick & easy.

Getting a memory address

FlamingoRider
P: 11
Hello. I know that this is probably going to be a really simple question but this is my first program that I'm trying to write in any program and I'm stumped. It's very short:

Expand|Select|Wrap|Line Numbers
  1. counter = 0
  2.  
  3. def letterSwitch1():
  4.     while counter <= number:
  5.         print "A" * number
  6.         print "B" * number
  7.         counter = counter + 1
  8.         return
  9.  
  10. number=raw_input("Enter a number: ")
  11.  
  12. print letterSwitch1
  13.  
  14.  
After I enter a number when running it I get: function letterSwitch1 at 0x00B3AFB0

I'm running XP and Python 2.6 using Cream/VIM
Feb 18 '09 #1
Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
I do not understand the purpose of the function letterSwitch1(). After making a few minor changes, it does something:
Expand|Select|Wrap|Line Numbers
  1. def letterSwitch1():
  2.     # move variable counter into function body
  3.     counter = 0
  4.     while counter <= number:
  5.         print "A" * number
  6.         print "B" * number
  7.         # use augmented addition
  8.         counter += 1
  9.     # change indentation so while loop will comnplete
  10.     # return statement is not required, function will return None anyway
  11.     return
  12.  
  13. # raw_input returns a string, type cast to int
  14. number=int(raw_input("Enter a number: "))
  15.  
  16. # No need to use print statement here
  17. # Add () to make function call
  18. letterSwitch1()
Output:
Expand|Select|Wrap|Line Numbers
  1. >>> AAAAAA
  2. BBBBBB
  3. AAAAAA
  4. BBBBBB
  5. AAAAAA
  6. BBBBBB
  7. AAAAAA
  8. BBBBBB
  9. AAAAAA
  10. BBBBBB
  11. AAAAAA
  12. BBBBBB
  13. AAAAAA
  14. BBBBBB
  15. >>> 
Feb 18 '09 #2

FlamingoRider
P: 11
Well, that was quite simple, I feel kinda stupid for not figuring it out myself. Thank you very much.
Feb 18 '09 #3

Post your reply

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