[Tutor] How to make the loop work?

2006-06-22 Thread Ivan Low
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?

Ivan
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to make the loop work?

2006-06-22 Thread Ivan Low
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


[Tutor] What is the square bracket about?

2006-07-22 Thread Ivan Low
def adder1(*args):
 print 'adder1',
 if type(args[0]) == type(0):
 sum = 0

 else:
 sum = args[0][:0]
 for arg in args:
 sum = sum + arg

 return sum

Hi, I was trying to understand what this function is all about.
I didn't tried the adder1 function which result in adding number or  
text together which I think there is an easier way to do it right?  
Why go through all the way to write a function like this?

The square is a big mystery to me. I can't explain why it is there.
I tried sum(1,2,3) and sum('a','b','c') it wouldn't work. I even  
search the document and I can't find anything there.

Ivan
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor