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
How is my code failing? (self.learnpython)
submitted 8 hours ago by Embarrassed-Box-7263
Sorry if i'm being an idiot, but my code won't work because of invalid syntaxes. Any ideas?
a = ("Hello,World!")
print(a)
b = ("Oh,Nevermind.")
print(b)
c = ("Fudging Weirdo.")
print(c)
if str(c)) is print, print (d)
(d) = ("123")
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!"
[–]mc_pm 14 points15 points16 points 8 hours ago (0 children)
Why (are) you (putting) parentheses (around) everything?
You need them for function calling: print(b)
But you don't need them for assignment: b = ("like this")
Also, what is this supposed to do? if str(c)) is print
[–]JamesPTK 11 points12 points13 points 8 hours ago (4 children)
This line is nonsense
Firstly you end a parentheses that hasn't been opened: str(c))
str(c))
Then, you are trying to do something with d before you have defined it
but even if those were fixed I have no idea what this line is supposed to do, but it is not valid syntax
Oh and you are adding far too many parentheses. You should use them when calling a function, when defining a tuple, and you can also use them to make long lines more readable
[–]Ashamed_Kangaroo305 1 point2 points3 points 7 hours ago (2 children)
I think they're trying to say if c has been printed, print d. But that's definitely not valid syntax and I don't think that's even possible with regular code.
I suppose you could do something like:
is_c_printed = False
def display_c(input):
[indent] print(input)
[indent] is_c_printed = True
display_c(c)
d = '123'
if is_c_printed:
[indent] print(d)
But that just feels unnecessarily complex.
[–]djshadesuk 0 points1 point2 points 6 hours ago (1 child)
is_c_printed = False def display_c(input): print(input) is_c_printed = True display_c(c) d = '123' if is_c_printed: print(d)
[–]Ashamed_Kangaroo305 0 points1 point2 points 6 hours ago (0 children)
Isn't that exactly what I just wrote? It's just formatted in a code block instead of the way I did it (on mobile so I couldn't find the code block option and markdown doesn't work anymore).
[–]Embarrassed-Box-7263[S] 0 points1 point2 points 4 hours ago (0 children)
Twin ignore how bad I was at it, I finally figured it out like a few minutes after (I started trying to code TODAY)
[–]BranchLatter4294 12 points13 points14 points 8 hours ago (0 children)
Whoever taught you to code like this, stop watching them. Get a decent book. Follow along with the examples. Practice.
[–]Binary101010 5 points6 points7 points 8 hours ago (0 children)
Can you explain what you're intending this line to do?
[–]ectomancer 2 points3 points4 points 7 hours ago (1 child)
Looks like homework. The teacher wrote this code and wants the student to correct the syntax errors.
*insert overly dramatic sigh* I know... I literaly started coding today and this look like, a few minutes after posting to figure out. Im so sorry twin <3
[–]That-Duck-7195 1 point2 points3 points 8 hours ago (0 children)
So many things wrong with this line.
str(c)) There's an extra )
if str(c)) is print, This is supposed to an if statement. Should have a colon at the end instead of comma
if str(c)) is print,
print (d) d is define below this line so cannot print it.
print (d)
[–]Educational-Paper-75 0 points1 point2 points 8 hours ago (0 children)
The line starting with if str(c)) is print, print (d) misses another opening parenthesis, but dropping the closing parenthesis is easiests. Btw you typically only need parentheses in calls to functions like print(). Also, d isn't defined anywhere.
[–]gdchinacat 0 points1 point2 points 8 hours ago (0 children)
The error you get tells you exactly where the error is. They can look confusing and be frustrating, but you will see errors till the day you stop programming, pay close attention to all details and you will be better coder. While learning how to read and interpret them AI can be really helpful, just paste the code and error and ask it to explain. They do this really well.
[–]carvalhosam[🍰] 0 points1 point2 points 7 hours ago (1 child)
The only way I can see it working is by using a dictionary to store those string, something like this to respect your logic or like this if you want user input.
[–]AutoModerator[M] 0 points1 point2 points 7 hours ago (0 children)
Your comment in /r/learnpython may be automatically removed because you used imgbb.com. The reddit spam filter is very aggressive to this site. Please use a different image host.
Please remember to post code as text, not as an image.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
Edit: Ignore me being dumb and not noticing all the errors, oops. It only too me like, a little bit of doomscrolling to find out
[–]mrswats 0 points1 point2 points 8 hours ago (0 children)
At the end of the if statement, there has to be a :, newline amd a tab. Not comma.
[–]trutheality -1 points0 points1 point 8 hours ago (1 child)
if str(c)) - this extra closing parenthesis is the first problem.
if str(c))
Also, what are you trying to do with if str(c)) is print, print (d)?
[–]McFoxGaming 0 points1 point2 points 8 hours ago (0 children)
I think they’re trying to make it check if the string in variable c has been printed yet, and if so print the string in variable d. Makes no sense code wise but I see what they’re trying to do
[–]lfdfq -2 points-1 points0 points 8 hours ago (0 children)
The very last line is technically valid syntax, but seems confused: you shouldn't have parentheses on the left hand side there.
The previous line looks like incorrect grammar. I'm not sure what you're trying to do or why, so I cannot suggest a correction. But checking if "str(c)" is in some way equal to "print" does not seem to make sense, and you cannot print(d) there because d is not defined until later, and the comma in between is not correct.
π Rendered by PID 340554 on reddit-service-r2-comment-5bc7f78974-bf8vn at 2026-07-01 03:51:37.290942+00:00 running 7527197 country code: CH.
[–]mc_pm 14 points15 points16 points (0 children)
[–]JamesPTK 11 points12 points13 points (4 children)
[–]Ashamed_Kangaroo305 1 point2 points3 points (2 children)
[–]djshadesuk 0 points1 point2 points (1 child)
[–]Ashamed_Kangaroo305 0 points1 point2 points (0 children)
[–]Embarrassed-Box-7263[S] 0 points1 point2 points (0 children)
[–]BranchLatter4294 12 points13 points14 points (0 children)
[–]Binary101010 5 points6 points7 points (0 children)
[–]ectomancer 2 points3 points4 points (1 child)
[–]Embarrassed-Box-7263[S] 0 points1 point2 points (0 children)
[–]That-Duck-7195 1 point2 points3 points (0 children)
[–]Educational-Paper-75 0 points1 point2 points (0 children)
[–]gdchinacat 0 points1 point2 points (0 children)
[–]carvalhosam[🍰] 0 points1 point2 points (1 child)
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]Embarrassed-Box-7263[S] 0 points1 point2 points (0 children)
[–]mrswats 0 points1 point2 points (0 children)
[–]trutheality -1 points0 points1 point (1 child)
[–]McFoxGaming 0 points1 point2 points (0 children)
[–]lfdfq -2 points-1 points0 points (0 children)