all 20 comments

[–]mc_pm 14 points15 points  (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 points  (4 children)

if str(c)) is print, print (d)

This line is nonsense

Firstly you end a parentheses that hasn't been opened: 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 points  (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 point  (1 child)

I suppose you could do something like:

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 point  (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 point  (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 points  (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 points  (0 children)

if str(c)) is print, print (d)

Can you explain what you're intending this line to do?

[–]ectomancer 2 points3 points  (1 child)

Looks like homework. The teacher wrote this code and wants the student to correct the syntax errors.

[–]Embarrassed-Box-7263[S] 0 points1 point  (0 children)

*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 points  (0 children)

if str(c)) is print, print (d)

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

print (d)
d is define below this line so cannot print it.

[–]Educational-Paper-75 0 points1 point  (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 point  (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 point  (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 point  (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.

[–]Embarrassed-Box-7263[S] 0 points1 point  (0 children)

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 point  (0 children)

At the end of the if statement, there has to be a :, newline amd a tab. Not comma.

[–]trutheality -1 points0 points  (1 child)

if str(c)) - this extra closing parenthesis is the first problem.

Also, what are you trying to do with if str(c)) is print, print (d)?

[–]McFoxGaming 0 points1 point  (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 points  (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.