944,162 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 1501
  • Python RSS
Nov 5th, 2009
0

How can I make a loop that changes?

Expand Post »
How do I make something like

Python Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
nevets04 is offline Offline
28 posts
since Oct 2009
Nov 5th, 2009
0
Re: How can I make a loop that changes?
A for loop is easier for this.

Python Syntax (Toggle Plain Text)
  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. >>>
Reputation Points: 280
Solved Threads: 281
Master Poster
snippsat is offline Offline
773 posts
since Aug 2008
Nov 5th, 2009
0
Re: How can I make a loop that changes?
Solved:
Python Syntax (Toggle Plain Text)
  1. List = []
  2. for x in xrange(5): List.append(raw_input(""))
Reputation Points: 10
Solved Threads: 1
Light Poster
nevets04 is offline Offline
28 posts
since Oct 2009
Nov 5th, 2009
0
Re: How can I make a loop that changes?
Yes good.
Or shorter.
Python Syntax (Toggle Plain Text)
  1. a = [raw_input('>')for x in range(5)]
Last edited by snippsat; Nov 5th, 2009 at 7:38 pm.
Reputation Points: 280
Solved Threads: 281
Master Poster
snippsat is offline Offline
773 posts
since Aug 2008
Nov 5th, 2009
0
Re: How can I make a loop that changes?
Click to Expand / Collapse  Quote originally posted by nevets04 ...
Solved:
Python Syntax (Toggle Plain Text)
  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.
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Nov 7th, 2009
0
Re: How can I make a loop that changes?
Click to Expand / Collapse  Quote originally posted by vegaseat ...
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; Nov 7th, 2009 at 6:22 pm.
Reputation Points: 10
Solved Threads: 1
Light Poster
nevets04 is offline Offline
28 posts
since Oct 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Cramer's Rule please
Next Thread in Python Forum Timeline: WxGlade does not show value





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC