Re: [Tutor] How to make the loop work?
It's basically correct but you need to convert the raw_input to integer. c=0 d=int(raw_input(input number limit: )) while 1: c = c + 1 if c == d: break print c ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to make the loop work?
Ivan Low wrote: Hi, I'm new to python trying to figure how to make this work. c=0;d=raw_input(input number limit: ) while 1: c = c + 1 if c == d: break print c, My idea is to able to input a number to limit the print out of this loop. But this will not work. Where is the error? Will not work does not (in general) give us enough to go on. Please in the future tell us what the evidence of the problem is - e.g. unexpected output, exception, ... If it is an exception please include the traceback in your post. -- Bob Gailer 510-978-4454 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to make the loop work?
Hi Bob, You can use a while loop in this case, but range() might be a bit more appropriate! c = 0 d = raw_input(Enter Number Limit: ) for i in range(int(d)): #note, we make sure d is an integer! c = c + 1 print cOn 6/22/06, Bob Gailer [EMAIL PROTECTED] wrote: Ivan Low wrote: Hi, I'm new to python trying to figure how to make this work. c=0;d=raw_input(input number limit: ) while 1: c = c + 1 if c == d: break print c, My idea is to able to input a number to limit the print out of this loop. But this will not work. Where is the error?Will not work does not (in general) give us enough to go on. Please in the future tell us what the evidence of the problem is - e.g. unexpectedoutput, exception, ... If it is an exception please include thetraceback in your post.--Bob Gailer510-978-4454___ Tutor maillist-Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to make the loop work?
Bob Gailer wrote: Ivan Low wrote: Hi, I'm new to python trying to figure how to make this work. c=0;d=raw_input(input number limit: ) while 1: c = c + 1 if c == d: break print c, My idea is to able to input a number to limit the print out of this loop. But this will not work. Where is the error? Will not work does not (in general) give us enough to go on. Please in the future tell us what the evidence of the problem is - e.g. unexpected output, exception, ... If it is an exception please include the traceback in your post. Hi, thanks for helping. After the reply from Peter by suggesting that I convert the raw_input to int, it works. Sorry that I didn't supply enough information in my post. However I'm curious about the result of my initial code after I enter a number which prompted by the raw_input it just keep printing numbers without break. Why is it acting like that? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to make the loop work?
Ivan Low wrote: Bob Gailer wrote: Ivan Low wrote: Hi, I'm new to python trying to figure how to make this work. c=0;d=raw_input(input number limit: ) while 1: c = c + 1 if c == d: break print c, My idea is to able to input a number to limit the print out of this loop. But this will not work. Where is the error? Will not work does not (in general) give us enough to go on. Please in the future tell us what the evidence of the problem is - e.g. unexpected output, exception, ... If it is an exception please include the traceback in your post. Hi, thanks for helping. After the reply from Peter by suggesting that I convert the raw_input to int, it works. Sorry that I didn't supply enough information in my post. However I'm curious about the result of my initial code after I enter a number which prompted by the raw_input it just keep printing numbers without break. Why is it acting like that? Python will compare any two objects. If their types are not compatible for comparison the result is False. Your program was comparing a character string to a numeric. Their types are not compatible. Hence always False. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Bob Gailer 510-978-4454 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor