[Tutor] Another Newbie question
Cédric Lucantis
omer at no-log.org
Tue Jun 24 12:56:45 CEST 2008
Le Tuesday 24 June 2008 12:23:41 Danny Laya, vous avez écrit :
> Hi I got some problem about writting convention in python. Some tutorial
> ask me to write this :
>
> a = 1
> s = 0
> print 'Enter Numbers to add to the sum.'
> print 'Enter 0 to quit.'
> while a != 0:
> print 'Current Sum:', s
> a = int(raw_input('Number? '))
> s = s + a
> print 'Total Sum =', s
>
> And the response must be like this :
>
>
> But when I write until this :
> >>> a = 1
> >>> s = 0
> >>> print 'Enter Numbers to add the sum'
>
> I press enter, and alas my python response me :
> Enter Numbers to add the sum
This is because you're doing this in an interactive session, so python
interprets and runs each line immediately after you write them. I guess this
example was supposed to be put in a file and executed from there, but you can
also put all this in a function :
def test_func() :
a = 1
s = 0
print 'Enter numbers to add to the sum.'
...
This won't do anything until you call the function:
test_func()
>
> It didn't want waiting me until I finish writing the rest.
> I know there is some mistake about my writing convention,
> but what ??? Can you find it ??
>
> But you know it's not finish,I ignore the error message and
>
> writng the rest, but until i write this:
> >>> while a != 0:
>
> .... print 'Current Sum:', s
> .... a = int(raw_input('Number?'))
> .... s = s+a
> .... print 'Total Sum =', s
>
> Oh, man... another error message :
>
> File "<stdin>", line 5
> print 'Total Sum =', s
> ^
You just forgot the most important: the error message itself :) Probably an
indentation error, but we'll need the full message to help (something
like "SomeError: blah blah...")
--
Cédric Lucantis
More information about the Tutor
mailing list