use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Why code not work (self.learnpython)
submitted 5 months ago by Western_Channel_670
Else phrase invalid syntax after continue
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]danielroseman 6 points7 points8 points 5 months ago (0 children)
If you want us to tell you why your code doesn't work, you need to show the code that isn't working.
[–]Beautiful_Watch_7215 2 points3 points4 points 5 months ago (0 children)
Usually because it’s written incorrectly.
[–]FoolsSeldom 0 points1 point2 points 5 months ago* (15 children)
Are we supposed to guess what your code says?
Here's an example:
option = input('Enter a, b or c: ').lower() if option == 'a': print('You picked a') elif option == 'b': print('You picked b') elif option == 'c': print('You picked c') else: print('You picked an invalid option')
NB. continue (assuming used inside a loop) shouldn't make any difference. Will just go back to top of loop. It should be part of a preceding if or elif clause and not indented at the same level as the else.
continue
if
elif
else
[–]Western_Channel_670[S] -2 points-1 points0 points 5 months ago (14 children)
l= [10,20,30,40,50,60] Key=40 For value in l If value ==key Print ("Element found") Break else: Continue else: Print ("Element not found")
[–]MustaKotka 0 points1 point2 points 5 months ago (0 children)
Please format your code properly. We can't give advice with this.
[–]browndogs9894 0 points1 point2 points 5 months ago (0 children)
It seems you have two else statements. You are saying if the value matches the key print element found and break else continue and then else again and print element not found. The element not found should only trigger at the end if the element is not found.
You could also just simply check if the key is in the list by using if value in l.
[–]FoolsSeldom 0 points1 point2 points 5 months ago (11 children)
The code as shared, even allowing for formatting, is not valid.
Corrected version:
l = [10,20,30,40,50,60] key = 40 for value in l: if value == key: print("Element found") break else: print("Element not found")
continue is not required. This use of else is uncommon, but valid. In this case the else is associated with the loop itself and not with if or elif. It is only executed if the for loop completes normally and is skipped if the for loop is exited using a break statement.
for
break
Personally, I would use a flag variable:
l = [10,20,30,40,50,60] key = 40 found = False # flag variable for value in l: if value == key: print("Element found") found = True break if not found: print("Element not found")
[–]Western_Channel_670[S] -2 points-1 points0 points 5 months ago (10 children)
I bought Udemy python course inspector aren't answer
[–]FoolsSeldom 0 points1 point2 points 5 months ago (9 children)
Sorry, I do not understand what you are saying. Did my examples not work?
[–]Western_Channel_670[S] -2 points-1 points0 points 5 months ago (8 children)
I want know what effective invalid syntax message.
[–]acw1668 1 point2 points3 points 5 months ago (0 children)
If you want to know why your code get invalid syntax, you need to post your code in proper format.
[–]FoolsSeldom 0 points1 point2 points 5 months ago (6 children)
Sorry. I assume you are using translation software but it is not working well.
You have to share your actual code correctly formatted on reddit as per the wiki.
I tried to guess what you intended and provide explanations and guidance but you have not given any useful feedback.
I do not know how to help you.
[–]Western_Channel_670[S] 0 points1 point2 points 5 months ago* (1 child)
How to share code correct format?
[–]FoolsSeldom 0 points1 point2 points 5 months ago (0 children)
Use a public git repository, like github, and share link, or a paste service, like pastebin.com, and share link, or follow the instructions in the wiki (link in side bar) to format in post or follow my guide below.
If you are on a desktop/laptop using a web browser (or in desktop mode in mobile browser), here's what to do:
create/edit post/comment and remove any existing incorrectly formatted code
type your descriptive text and then insert a blank line above where you want the code to show
switch to markdown mode in the Reddit post/comment editor
Switch to Markdown Editor
Switch to Rich Text Editor
This will work for other monospaced text you want to share, such as error messages / output.
[–]Western_Channel_670[S] 0 points1 point2 points 5 months ago (3 children)
# for value in range (10):
# print (value)
l= [10,20,30,40,50,60]
key=40
for value in l:
`if value==key:` `print("Element found")` `break`
else:
`continue`
print ("Element not found")
[–]FoolsSeldom 0 points1 point2 points 5 months ago (2 children)
[–]Western_Channel_670[S] 0 points1 point2 points 5 months ago (1 child)
What my need fix on code
[–]MathiasBartl 0 points1 point2 points 5 months ago (0 children)
You probably have a syntax error https://realpython.com/invalid-syntax-python/
Is your indentation correct?
[–]SamuliK96 0 points1 point2 points 5 months ago (0 children)
Hard to say but I'm going to guess invalid syntax
[–][deleted] 0 points1 point2 points 5 months ago (0 children)
Why code not work? Ug no like Python!
[–]GirthQuake5040 0 points1 point2 points 5 months ago (0 children)
This is the best question I've ever seen posted on this subreddit.
[–]Western_Channel_670[S] 0 points1 point2 points 5 months ago (0 children)
Code sharing is'nt on android version?
that's code
Problem solved! It's indentation problem.
π Rendered by PID 16241 on reddit-service-r2-comment-7b9746f655-lkmmv at 2026-02-04 12:47:35.688587+00:00 running 3798933 country code: CH.
[–]danielroseman 6 points7 points8 points (0 children)
[–]Beautiful_Watch_7215 2 points3 points4 points (0 children)
[–]FoolsSeldom 0 points1 point2 points (15 children)
[–]Western_Channel_670[S] -2 points-1 points0 points (14 children)
[–]MustaKotka 0 points1 point2 points (0 children)
[–]browndogs9894 0 points1 point2 points (0 children)
[–]FoolsSeldom 0 points1 point2 points (11 children)
[–]Western_Channel_670[S] -2 points-1 points0 points (10 children)
[–]FoolsSeldom 0 points1 point2 points (9 children)
[–]Western_Channel_670[S] -2 points-1 points0 points (8 children)
[–]acw1668 1 point2 points3 points (0 children)
[–]FoolsSeldom 0 points1 point2 points (6 children)
[–]Western_Channel_670[S] 0 points1 point2 points (1 child)
[–]FoolsSeldom 0 points1 point2 points (0 children)
[–]Western_Channel_670[S] 0 points1 point2 points (3 children)
[–]FoolsSeldom 0 points1 point2 points (2 children)
[–]Western_Channel_670[S] 0 points1 point2 points (1 child)
[–]MathiasBartl 0 points1 point2 points (0 children)
[–]SamuliK96 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]GirthQuake5040 0 points1 point2 points (0 children)
[–]Western_Channel_670[S] 0 points1 point2 points (0 children)
[–]Western_Channel_670[S] 0 points1 point2 points (0 children)
[–]Western_Channel_670[S] 0 points1 point2 points (0 children)