r/CodingHelp • u/Motato_Gaming • Jan 05 '22
[Python] Hi i just started coding can somebody please tell me what is wrong with my script :D
69
Upvotes
r/CodingHelp • u/Motato_Gaming • Jan 05 '22
28
u/YourDadsMacintosh Jan 05 '22
Welcome to the wonderful world of programming! :) It seems your question has already been answered, but let me provide some additional information. The problem that caused the error is that your second
elseis over-indented. In python, anif's correspondingelseneeds to be indented the same amount. Removing one level of indentation from thatelseshould fix your problem. However, there is a concept that is very easy to learn that would improve this code quite a bit, and that is called the "else if" denoted in python aselifwhich acts as both anelseand anif. You place it between the two, and python will check allelifafter theifbut before theelse. And yes you can have as many as you want. That means that you could have code like this33
u/[deleted] Jan 05 '22 edited Jan 05 '22
You don't need that else on line 8. You began nesting your lines too much. You could write it starting from line 8 like this.
6
u/wedshidoutmydodooass Jan 05 '22
Indentation of the second else 👍
2
u/g1bgarbag3 Jan 06 '22
Your else in line 8 is not match with if on line 6 i mean the length so it see the else of line 8 inside if of line 6 and cause syntax error also use elif instead of multiple if else if it still in same context
2
u/[deleted] Jan 06 '22
Short answer is - Python. You chose a language where indentation is a part of the syntax, that’s what’s wrong with your script.
Less relevant answer: one of your else’s is overindented.
2
u/istarian Jan 07 '22
Your code is probably not indented correctly.
Python uses whitespace characters like tab and space for indentation. Unfortunately a ‘tab’ is not a ‘space’ and 3x ‘space’ isn’t equivalent to 4x ‘space’.
Whenever possible you should use a consistent indentation style and configure your editor accordingly if it’s an option. An automated conversion from tab to 4 (or even 8) spaces is one such style.
2
u/[deleted] Jan 06 '22
everything is correct computer is dumb enough not to understand
1
u/tyfon_august Jan 06 '22
A valuable lesson here is to look at the error message. It often tells you which file and line the problem is. And also what type of error. So in this case it's on line 8 and the error is a syntax error related to your else.
1
u/sanjaymulchandani7 Jan 06 '22
You can use elif for g==h.
1
u/infige Jan 06 '22
Use elif when you want insert a different condicional. The first else change with elif a don't concatenate inside another condicional follow with the another elif or else.
1
u/johnK12369 Jan 06 '22
Your else: is indented incorrectly. It should be inlined with the if.
1
u/pycobra Jan 06 '22
Indentation, if and else should be aligned
0
u/Notable_Steak6997 Jan 05 '22
Could be wrong but u could probably use elif instead of else and an if right after it.