How can I make a loop that changes?

Thread Solved

Join Date: Oct 2009
Posts: 21
Reputation: nevets04 is an unknown quantity at this point 
Solved Threads: 0
nevets04 nevets04 is offline Offline
Newbie Poster

How can I make a loop that changes?

 
0
  #1
19 Days Ago
How do I make something like

  1. x = 5
  2. while 0 < x
  3. b = raw_input("something: ")

However each time it loops, I want it to change, like:
first loop - b = raw_input("something: ")
second loops - c = raw_input("something: ")
third loop - d = raw_input("something: ")
and so on.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 146
Reputation: snippsat is an unknown quantity at this point 
Solved Threads: 42
snippsat snippsat is offline Offline
Junior Poster
 
0
  #2
19 Days Ago
A for loop is easier for this.

  1. for i in range(4):
  2. for item in ['a,b,c,d']:
  3. item = raw_input("something: ")
  4.  
  5. something: 7
  6. something: 8
  7. something: 9
  8. something: 2
  9. >>> item
  10. '2'
  11.  
  12. >>> #If you whant to store all values put them into a list
  13. >>> l = []
  14. for i in range(4):
  15. for item in ['a,b,c,d']:
  16. item = raw_input("something: ")
  17. l.append(item)
  18.  
  19.  
  20. something: 8
  21. something: 9
  22. something: 6
  23. something: test
  24. >>> l
  25. ['8', '9', '6', 'test']
  26. >>>
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 21
Reputation: nevets04 is an unknown quantity at this point 
Solved Threads: 0
nevets04 nevets04 is offline Offline
Newbie Poster
 
0
  #3
19 Days Ago
Solved:
  1. List = []
  2. for x in xrange(5): List.append(raw_input(""))
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 146
Reputation: snippsat is an unknown quantity at this point 
Solved Threads: 42
snippsat snippsat is offline Offline
Junior Poster
 
0
  #4
19 Days Ago
Yes good.
Or shorter.
  1. a = [raw_input('>')for x in range(5)]
Last edited by snippsat; 19 Days Ago at 7:38 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,959
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 918
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite
 
0
  #5
19 Days Ago
Originally Posted by nevets04 View Post
Solved:
  1. List = []
  2. for x in xrange(5): List.append(raw_input(""))
Wow, I would have never guessed that from your original question.

Hint, variable names starting with a capital letter are by convention used for class names.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 21
Reputation: nevets04 is an unknown quantity at this point 
Solved Threads: 0
nevets04 nevets04 is offline Offline
Newbie Poster
 
0
  #6
17 Days Ago
Originally Posted by vegaseat View Post
Wow, I would have never guessed that from your original question.

Hint, variable names starting with a capital letter are by convention used for class names.
Lol. Yeah, I wasn't really sure how to phrase that question
Last edited by nevets04; 17 Days Ago at 6:22 pm.
Reply With Quote Quick reply to this message  
Reply

Tags
loop, variable

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC