Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.
Login
Login
OnlineGDB Q&A
Questions
Unanswered
Tags
Ask a Question
Ask a Question
elif syntax error
+3
votes
asked
Nov 4, 2021
by
Princess
(
160
points)
I am using an elif statement and it is giving me a syntax error. Why is that?
-conditions
please-help-python
syntax-error
beginner
Your answer
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
2 Answers
+2
votes
answered
Nov 5, 2021
by
1221 Swetha
(
190
points)
we should write conditions for if and elif along with the indentation (indentation gap should be equal for every statement)
if(condition):
statements
elif(condition):
statements
else:
statements
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
+3
votes
answered
Nov 5, 2021
by
Peter Minarik
(
79,780
points)
Could you please share your code?
Probably you missed something (e.g. a colon).
commented
Nov 12, 2021
by
Princess
(
160
points)
https://onlinegdb.com/GbNyEFUAa
here it is
commented
Nov 12, 2021
by
Peter Minarik
(
79,780
points)
There are colons missing from the end of the lines of if/else statements and also your indentation is wrong.
It's fixed here:
https://onlinegdb.com/vZhz8uXjc
commented
Nov 12, 2021
by
Princess
(
160
points)
thank you so much!
commented
Nov 12, 2021
by
Princess
(
160
points)
i dont mean to disturb you but I was also having an issue with running this code:
https://onlinegdb.com/fhiflHgiB
commented
Nov 13, 2021
by
Peter Minarik
(
79,780
points)
You did not close one of the parentheses and had the commas on the left side of the quotation mark, but they should have gone to the right side.
Your code fixed is here:
https://onlinegdb.com/JfMYt00G4
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...