Python Forum

Full Version: "Invalid Syntax" (I am a new coder)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I started to learn programming yesterday and today I wanted to make a function about our grade system. Unfortunatley i don't know why i got "SyntaError: invalid syntax"

This was my code:

def merit(a, b, c, d, e, f, m):
return ((a * 2000 + b * 1750 + c * 1500 + d * 1250 + e * 1000 + f* 0)/(100 * (a + b + c + d + e + f)) + m)
freshman_grades = merit(4, 2, 0, 0, 0, 0, 2.5)
SyntaxError: invalid syntax, it also underlines "freshman_grades" for some reason.

Appreciate any help I can get!

/Marius
you must indent the line after def

def merit(a, b, c, d, e, f, m):
    return ((a * 2000 + b * 1750 + c * 1500 + d * 1250 + e * 1000 + f* 0)/(100 * (a + b + c + d + e + f)) + m)
freshman_grades = merit(4, 2, 0, 0, 0, 0, 2.5)
print(freshman_grades)
(Sep-07-2018, 09:13 PM)Axel_Erfurt Wrote: [ -> ]you must indent the line after def

def merit(a, b, c, d, e, f, m):
          return ((a * 2000 + b * 1750 + c * 1500 + d * 1250 + e * 1000 + f* 0)/(100 * (a + b + c + d + e + f)) + m)
freshman_grades = merit(4, 2, 0, 0, 0, 0, 2.5)
print(freshman_grades)

Sorry for the bad presentation of my code but i have actually indented my code, I can't get the indention to show up though D:

When i copied your code i still got Invalid Syntax, which is very weird.

Thanks anyways!
No syntax errors there. Are you perhaps mixing tabs and spaces?
Please post a copy of your exact error.
def merit(a, b, c, d, e, f, m):
	return ((a * 2000 + b * 1750 + c * 1500 + d * 1250 + e * 1000 + f * 0)/(100 * (a + b + c + d + e + f)) + m)
freshman_grades = merit(4, 2, 0, 0, 0, 0, 2.5)
There you go! It seems to think that freshman_grades is the error for some reason.
(Sep-07-2018, 09:17 PM)Marius2002 Wrote: [ -> ]Sorry for the bad presentation of my code but i have actually indented my code, I can't get the indention to show up though D:
Look at BBCode.
(Sep-07-2018, 09:17 PM)Marius2002 Wrote: [ -> ]When i copied your code i still got Invalid Syntax, which is very weird.
Do you copy into IDLE, has >>> ?
It's for interactive testing line bye line based.

If copy in whole code has to use New File.
The a new window open,paste or write in code as save with .py extension.
Run -> Run Module(F5).
(Sep-07-2018, 09:39 PM)snippsat Wrote: [ -> ]
(Sep-07-2018, 09:17 PM)Marius2002 Wrote: [ -> ]Sorry for the bad presentation of my code but i have actually indented my code, I can't get the indention to show up though D:
Look at BBCode.
(Sep-07-2018, 09:17 PM)Marius2002 Wrote: [ -> ]When i copied your code i still got Invalid Syntax, which is very weird.
Do you copy into IDLE, has >>> ?
It's for interactive testing line bye line based.

If copy in whole code has to use New File.
The a new window open,paste or write in code as save with .py extension.
Run -> Run Module(F5).

Could you rephrase that a little, since I am very new i can't really understand what you mean.
What do you use to run your code and OS as python works on all platforms Windows,Linux and Mac.
IDLE can often be what people start with.
Here image i used before to explain it.
[Image: Wn7asS.jpg]
(Sep-07-2018, 10:15 PM)snippsat Wrote: [ -> ]What do you use to run your code and OS as python works on all platforms Windows,Linux and Mac.
IDLE can often be what people start with.
Here image i used before to explain it.
[Image: Wn7asS.jpg]

Thnak you so much! Now it works!