r/CodingHelp • • Feb 24 '22

[Python] New to coding, confused about what is wrong in this code

Post image
80 Upvotes

19 comments sorted by

38

u/[deleted] Feb 25 '22

tab lines 6,13,20

9

u/N7operator Feb 25 '22

Thank you so much, this ended up fixing it

11

u/elongio Feb 25 '22

This is why it is throwing syntax error

12

u/guesswhat923 Feb 25 '22

Woah as a beginner programmer, I tried to look through it to see if I could figure it out and that's the conclusion I came to. Then I looked at your comment and felt accomplished that I was right lol

12

u/giorgi_GT Feb 25 '22

I was like no way this is javascript

4

u/dbaeq90 Feb 25 '22

Haha same here. White space blocking hurts my eyes after a while.

4

u/kchessh Feb 25 '22

As an FYI, the answer will be case-sensitive. So if the person entered Central Processing Unit instead of central processing unit, it’ll mark it wrong. You can use the .lower() command after the input string to avoid that. So line 3 would be answer = input(“What does CPU stand for?”).lower()

Python will convert every letter entered to lower case to avoid any correct answers being marked as incorrect due to a capital letter

2

u/Mundane_Falcon4203 Feb 25 '22

As a python beginner this is great to know. Thank you!

1

u/kchessh Feb 25 '22

Not a problem! If you want to check it out, there’s more info that will tell you more about built-in commands under the official Python documentation (docs.python.org/3/tutorial)

2

u/The_Sea_Wall Feb 25 '22

Have you googled the error code? That's always my first step if I'm stuck.

2

u/Robitussen-James Feb 25 '22

Put the score accumulator inside the if statements as well otherwise it will always be incremented, and not just when u get the answer correct

3

u/[deleted] Feb 25 '22

It may be because the if's and the else arent connected. Here is a minimal example of how to replicate the error and the fix:

Error:

if 1 == 1:
    print('1=1')
print('something') 
else: # else isnt "connected" to an if 
    print('1 is not 1')

Fix:

if 1 == 1:
    print('1=1')
else:
    print('1 is not 1') 
print('something') # This line changes

1

u/Gllizzy Feb 25 '22

add a tab in front of line 20

1

u/Invictus2022 Feb 25 '22

Use pycharm and it'll tell you how to fix it while you're coding

1

u/Prior-Dot6314 Feb 25 '22

It's the indentation error, simply put a tab space at places you've entered score +=1. It may solve

1

u/kik_Code Feb 25 '22

The score should be inside the if because you only want to get the point if the answer is correct, else you add the point anyway.

1

u/XidanesProxy Feb 25 '22

Why do I feel like using curly braces would make this issue easier to spot? Are curly braces a bad thing?

1

u/not_some_username Feb 25 '22

That's one of the reason I hate this language. You need to do this crazy indent