[Tutor] Hello and some questions.

Andre Engels andreengels at gmail.com
Mon Sep 29 01:52:57 CEST 2008


On Mon, Sep 29, 2008 at 1:36 AM,  <tsmundahl at comcast.net> wrote:

> I did get some help in the python forums with this and I have come up the following, but I am getting a syntax error on the line that calls out "total" as a variable. Here is the code:

The actual problem is in the previous line:

    print (int(float(raw_input("Please enter a grade, use numbers 1 - 10: ")))

If you count, there are 4 (s and 3 )s in there. Because every ( should
have a corresponding ) and vice versa, Python thinks that this
statement has not finished yet. It gives a syntax error at the _next_
line, because there it finds something that cannot be a correct
continuation of this statement.

However, even if you would do that, the result would still not be what
you want. It will give 0 each time, because value will always be the
empty list. Rather than printing out the grade that the user entered,
you would want to put it in the list value (an unlucky choice of a
name for a list of grades, in my opinion)

> The next problem is supposed to use the while loop. A user is supposed to enter some grade values. The user will continue to be prompted to enter grade values until the user has entered in "9999" as  a grade value. Then the program is supposed to calculate the average of all of the grades entered including the 9999.
>
> Here is my code, This code is not working either:
>
> target = 9999
>
> value = [ ]
>
> while i in value < or not == target:

That line will indeed cause Python to stumble. I'm not even sure what
you want to do here, so I can't really say what it should have been.

-- 
André Engels, andreengels at gmail.com


More information about the Tutor mailing list