Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,224 members, 7,818,766 topics. Date: Monday, 06 May 2024 at 01:21 AM

Help Python Syntax Error! - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help Python Syntax Error! (878 Views)

My PHP Code Run Locally On XAMPP But Showing Syntax Error Online / Programmers Help:python Code To Acess Laptop/desktop Camera / I Have A Very Import Question On Python Syntax (2) (3) (4)

(1) (Reply) (Go Down)

Help Python Syntax Error! by ReignDigitals(m): 1:16pm On Aug 15, 2020
Hello programmers in the house. I'm learning python. I came across this code on this forum and I decided to try it out. After I finished running it, I got error saying INVALID SYNTAX.

Please someone should help me and fix it.



Name=input('What is your full Name?')
Matric_number=input('What is your Matric Number?')
Course_code=input('What is yout course code?')
Score=int(input('What is your score?(score must not exceed 100)'))

if Score >100:
print("invalid score"wink
elif Score <=100 and Score >=70:
Score ='A'
elif Score <=69 and Score >=60:
Score ='B'
elif Score <=59 and Score >=50:
Score ='C'
elif Score <=49 and Score >=40:
Score ='D'
elif Score <=39 and Score >=30:
Score ='E'
else:
Score ='F'

print (f'{Name} with a Matric No of, {Matric_number} at the end of the Semester, had Grade {Score} in {Course_code}')

Re: Help Python Syntax Error! by Meel: 1:56pm On Aug 15, 2020
Name=input('What is your full Name?')
Matric_number=input('What is your Matric Number?')
Course_code=input('What is yout course code?')
Score=int(input('What is your score?(score must not exceed 100)'))
if Score >100:
print("invalid score"wink
elif Score <=100 and Score >=70:
Score ='A'
elif Score <=69 and Score >=60:
Score ='B'
elif Score <=59 and Score >=50:
Score ='C'
elif Score <=49 and Score >=40:
Score ='D'
elif Score <=39 and Score >=30:
Score ='E'
else:
Score ='F'
print (f'{Name} with a Matric No of, {Matric_number} at the end of the Semester, had Grade {Score} in {Course_code}')
Re: Help Python Syntax Error! by DriggityDre: 2:32pm On Aug 15, 2020
To be honest, I can't see anything. What are you trying to do exactly?

Oh, now I see it.
Re: Help Python Syntax Error! by DriggityDre: 2:40pm On Aug 15, 2020
Meel:

Name=input('What is your full Name?')
***
Wha? I thought you answered it. This is literally the same thing.
Re: Help Python Syntax Error! by Meel: 2:45pm On Aug 15, 2020
DriggityDre:
Wha? I thought you answered it. This is literally the same thing.
try and work on your indentation.
and check this( print("invalid score" ) for closing parentheses.

Re: Help Python Syntax Error! by DriggityDre: 2:48pm On Aug 15, 2020
Meel:

try and work on your indentation.

and check this( print("invalid score" ) for closing parentheses.
No be me be that o grin.. but at least, you've solved it. I didn't see that at first.

You can use the code tag: [cøde][/cøde] to preserve indentation on NL.

Like this;


print( "Enter your Nairaland Username: " )
else:
print ( "........" )
Re: Help Python Syntax Error! by ReignDigitals(m): 4:12pm On Aug 15, 2020
Meel:


try and work on your indentation.

and check this( print("invalid score" ) for closing parentheses.

Please I'm Still getting error. Expected an indent block. I have tried every method but no way. Could you please paste your own code?
Re: Help Python Syntax Error! by Meel: 4:25pm On Aug 15, 2020
ReignDigitals:


Please I'm Still getting error. Expected an indent block. I have tried every method but no way. Could you please paste your own code?
it seems you have not comprehended the use if indentation.

when debugging, try to read the error.Here the system will indicate the line the error occurred.

lemme see your code

Re: Help Python Syntax Error! by Meel: 4:28pm On Aug 15, 2020
DriggityDre:

No be me be that o grin.. but at least, you've solved it. I didn't see that at first.

You can use the code tag: [cøde][/cøde] to preserve indentation on NL.

Like this;


print( "Enter your Nairaland Username: " )
else:
print ( "........" )

wow, never knew nairaland has such option.
Thanks.


Name=input('What is your full Name?')
Matric_number=input('What is your Matric Number?')
Course_code=input('What is yout course code?')
Score=int(input('What is your score?(score must not exceed 100)'))
if Score >100:
print("invalid score" )
elif Score <=100 and Score >=70:
Score ='A'
elif Score <=69 and Score >=60:
Score ='B'
elif Score <=59 and Score >=50:
Score ='C'
elif Score <=49 and Score >=40:
Score ='D'
elif Score <=39 and Score >=30:
Score ='E'
else:
Score ='F'
print (f'{Name} with a Matric No of, {Matric_number} at the end of the Semester, had Grade {Score} in {Course_code}')

1 Like

Re: Help Python Syntax Error! by ReignDigitals(m): 4:42pm On Aug 15, 2020
Meel:

it seems you have not comprehended the use if indentation.

when debugging, try to read the error.Here the system will indicate the line the error occurred.

lemme see your code

Here it is

Re: Help Python Syntax Error! by Vecto(m): 9:12pm On Aug 15, 2020
Meel:

it seems you have not comprehended the use if indentation.

when debugging, try to read the error.Here the system will indicate the line the error occurred.

lemme see your code

What app is this?
Re: Help Python Syntax Error! by Daejoyoung: 10:06pm On Aug 15, 2020
ReignDigitals:


Here it is
Your indentation is not consistent.
Check your indentation after the else conditional statement.
Re: Help Python Syntax Error! by peppo4live: 11:00pm On Aug 15, 2020
ReignDigitals:


Here it is

After I input 101 as my score

It displayed invalid score but still continued with the print statement... I thought the program should end at invalid score ...

Any input will be appreciated
Re: Help Python Syntax Error! by Taofeekdboy(m): 5:42am On Aug 16, 2020
peppo4live:


After I input 101 as my score

It displayed invalid score but still continued with the print statement... I thought the program should end at invalid score ...

Any input will be appreciated
It will print the statement because the print statement is at the end of if/else block, so no matter what the situation or output of your code, there will always be a print statement, one solution is to move the print statement to each of the elif block and remove it from if statement greater than 100. Meanwhile, this code has some bugs, there is no validation whatsoever, what if I input a string instead of a number, it will break your application, any inputation code requires input validation.

1 Like

Re: Help Python Syntax Error! by Regex: 9:52am On Aug 16, 2020
Here is mine, I can't seem to see the problem here. But the code has a lot of bug.

Re: Help Python Syntax Error! by Nobody: 12:25pm On Aug 16, 2020
If you have the chance, consider coding with a computer.
Download Sublime text or vs code
Or
Download an ide like PyCharm.

This will help you on the long run.
Re: Help Python Syntax Error! by naijasensei: 2:50pm On Aug 16, 2020
ReignDigitals:
Hello programmers in the house. I'm learning python. I came across this code on this forum and I decided to try it out. After I finished running it, I got error saying INVALID SYNTAX.

Please someone should help me and fix it.



Name=input('What is your full Name?')
Matric_number=input('What is your Matric Number?')
Course_code=input('What is yout course code?')
Score=int(input('What is your score?(score must not exceed 100)'))

if Score >100:
print("invalid score"wink
elif Score <=100 and Score >=70:
Score ='A'
elif Score <=69 and Score >=60:
Score ='B'
elif Score <=59 and Score >=50:
Score ='C'
elif Score <=49 and Score >=40:
Score ='D'
elif Score <=39 and Score >=30:
Score ='E'
else:
Score ='F'

print (f'{Name} with a Matric No of, {Matric_number} at the end of the Semester, had Grade {Score} in {Course_code}')


First off, what version of Python are you using? Your last print statement is using an "f string", this feature is only supported in versions 3.6 onwards. Also, there seems to be a space between your print and the beginning parentheses of the print function "print (". Delete that space.
Secondly, try to do things the python way. It is recommended to always begin your variable names (and also function names) with lowercase letters, you can use the underscore (_) for compound words. Class names on the other hand should begin with uppercase letters.
Thirdly, why are you assigning grades and scores to the same variable (Score) in your if...else block? Why not create another variable (eg grade) to store the grades? If you need the score value later, you will still be able to use it.
Re: Help Python Syntax Error! by naijasensei: 3:17pm On Aug 16, 2020
Regex:
Here is mine, I can't seem to see the problem here. But the code has a lot of bug.

Try this on your last line:

print("%s with a Matric No of, %s at the end of the Semester, had Grade %s in %s" %(name, matricNumber, score, courseCode))

Note the space between the second " and the %() function. Also try using snake case (matric_number) instead of camel case (matricNumber) when naming variables, it is the Python way. I would recommend assigning the grade to another variable instead of overwriting what is in score.
Re: Help Python Syntax Error! by Regex: 3:25pm On Aug 16, 2020
naijasensei:


Try this on your last line:

print("%s with a Matric No of, %s at the end of the Semester, had Grade %s in %s" %(name, matricNumber, score, courseCode))

Note the space between the second " and the %() function. Also try using snake case (matric_number) instead of camel case (matricNumber) when naming variables, it is the Python way. I would recommend assigning the grade to another variable instead of overwriting what is in score.

OK will do. Thank you BTW.

1 Like

Re: Help Python Syntax Error! by SirMichael1: 11:13am On Aug 29, 2020
naijasensei:


First off, what version of Python are you using? Your last print statement is using an "f string", this feature is only supported in versions 3.6 onwards. Also, there seems to be a space between your print and the beginning parentheses of the print function "print (". Delete that space.
Secondly, try to do things the python way. It is recommended to always begin your variable names (and also function names) with lowercase letters, you can use the underscore (_) for compound words. Class names on the other hand should begin with uppercase letters.
Thirdly, why are you assigning grades and scores to the same variable (Score) in your if...else block? Why not create another variable (eg grade) to store the grades? If you need the score value later, you will still be able to use it.

The boldened is insightful. You could begin to get errors when trying to carry out arithmetic operations with the 'score' variable. Make I follow you. I like people wey smart.
Re: Help Python Syntax Error! by naijasensei: 11:40am On Aug 29, 2020
SirMichael1:


The boldened is insightful. You could begin to get errors when trying to carry out arithmetic operations with the 'score' variable. Make I follow you. I like people wey smart.

We are all smart, we just need to unleash our inner smartness.
Re: Help Python Syntax Error! by SirMichael1: 11:44am On Aug 29, 2020
naijasensei:


We are all smart, we just need to unleash our inner smartness.
That's true. I appreciate the follow back. Means a lot.

1 Like

(1) (Reply)

Self-taught Programmers / Vb 6.0 Newbie / They Are In Nigeria Now!

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 38
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.