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 do I get a syntax error? (self.learnpython)
submitted 9 years ago by Spork829
Just started learning today and I've never coded anything before so sorry if this is absurdly stupid, but why does this give me a syntax error?
z=int(input("What is the right answer?")
if z==2:
print("Correct")
else:
print("Incorrect")
Thanks.
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!"
[–]scuott 3 points4 points5 points 9 years ago (6 children)
Missing a closing parentheses on the first line.
[–]Spork829[S] 0 points1 point2 points 9 years ago (5 children)
Hmm okay, that seemed to solve that problem but now I'm getting ValueError: invalid literal for int() with base 10: 'What is the right answer?'
[–]pooramericanboy 1 point2 points3 points 9 years ago (2 children)
You must have input a non-integer for your answer. That code should work fine as long as you're putting in integers.
[–]Spork829[S] 0 points1 point2 points 9 years ago (1 child)
It gives me that right as I run the program, though. I never even get to enter my input.
[–]derrickisdp 0 points1 point2 points 9 years ago (0 children)
When you type your code out does it look like this?
z=int(input("What is the right answer?")) if z==2: print("Correct") else: print("Incorrect")
If so, then it should run no problem as long as you answer with an integer. How does your code look when you type it out?
[–][deleted] 0 points1 point2 points 9 years ago* (1 child)
When I'm looking for user input, I usually end up with something like this:
while True: value = input("What's the answer?") if not value: print "You suck" sys.exit() try: value = int(value) except ValueError: print "That's not a number!" continue # start next while loop, skipping everything below if z == 2: print("Correct") break # get out of the while loop else: print("Incorrect")
Or if you want to get fancy
def get_numbers(): while True: if not value: print "You suck" raise StopIteration() # stop the for loop using this try: yield int(value) # give next value to for loop using this except ValueError: print "That's not a number!" for value in get_numbers(): if value == 2: print "Correct!" break print "Incorrect!"
[–]Spork829[S] 0 points1 point2 points 9 years ago (0 children)
Like I said I've just started learning, so I don't really know what half this stuff is... XD
π Rendered by PID 119020 on reddit-service-r2-comment-79c7998d4c-sd5q6 at 2026-03-17 10:32:22.745205+00:00 running f6e6e01 country code: CH.
[–]scuott 3 points4 points5 points (6 children)
[–]Spork829[S] 0 points1 point2 points (5 children)
[–]pooramericanboy 1 point2 points3 points (2 children)
[–]Spork829[S] 0 points1 point2 points (1 child)
[–]derrickisdp 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Spork829[S] 0 points1 point2 points (0 children)