Ask coding questions

← Back to all posts
why doesn't this print?
Trex10 (7)

the print statement on line 40 in this code is just makin an empty line instead of printing what I want. But if I put it up onto line 33, it does print. Why is this?

Comments
hotnewtop
RYANTADIPARTHI (6001)

you don't seem to be using correct if statements. They seem to be getting mixed up with others.

Trex10 (7)

@RYANTADIPARTHI
how would I change it to be correct if statements?

Trex10 (7)

@RYANTADIPARTHI
My if and elif statements are on the same indentation level but it still doesn't work properly.

elipie (364)

one reason may be: Your python code is too cluttered, a way to fix this is to actually use the lex/parse method to create a language, and it is just way much easier to understand, I tried creating a language like this and it was extremeley hard when I got to if statements, functions, so on.

Another reason is maybe because there is something wrong with your elif statements

other than that i do not know

Trex10 (7)

@elipie
what's the lex/parse method?

elipie (364)

@Trex10 its kind of hard to explain, but just google it.

It basically takes the source code and the lexer turns it to tokens, then sends that to the parser and then the parser makes an ast, abstract syntax tree, then that goes to the compiler or interpreter, which then executes the code.

Yeah just google it