"Invalid Syntax" (I am a new coder) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: "Invalid Syntax" (I am a new coder) (/thread-12691.html) |
"Invalid Syntax" (I am a new coder) - Marius2002 - Sep-07-2018 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 RE: "Invalid Syntax" (I am a new coder) - Axel_Erfurt - Sep-07-2018 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) RE: "Invalid Syntax" (I am a new coder) - Marius2002 - Sep-07-2018 (Sep-07-2018, 09:13 PM)Axel_Erfurt Wrote: you must indent the line after def 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! RE: "Invalid Syntax" (I am a new coder) - Mekire - Sep-07-2018 No syntax errors there. Are you perhaps mixing tabs and spaces? Please post a copy of your exact error. RE: "Invalid Syntax" (I am a new coder) - Marius2002 - Sep-07-2018 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. RE: "Invalid Syntax" (I am a new coder) - snippsat - Sep-07-2018 (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). RE: "Invalid Syntax" (I am a new coder) - Marius2002 - Sep-07-2018 (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. Could you rephrase that a little, since I am very new i can't really understand what you mean. RE: "Invalid Syntax" (I am a new coder) - snippsat - Sep-07-2018 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. RE: "Invalid Syntax" (I am a new coder) - Marius2002 - Sep-08-2018 (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. Thnak you so much! Now it works! |