Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Whenever I write elif or else in my code I get a Syntax Error. Why is this?

I am trying to write code for a simple Rock Paper Scissors and I got stuck here because else or elif don’t work in my code. This is my code

I tried looking up why this didn’t work and I couldn’t find anything on the subject.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It seems you are mixing the order how to use if-elif-else.

Following is quoted from (and I recommend to check it deeper):
if, elif and else.. priority and chains

"else is the catch-all after all the if and elif statements were false. Putting it in the middle would be a syntax error.

if False:
print ‘first’
elif True:
print ‘second’
elif True:
print ‘third’ "

Happy coding!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading