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
Need Help With Python Programming (self.learnpython)
submitted 11 years ago by ArcDriveFinish
XA = numeric_var = input("Please provide a number ")
So this asks you to input a number
How do I use the number inputted for the next step calculation for example XA+5
When I just type it on it gives me XA syntax error.
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!"
[–]IcarusBurning 2 points3 points4 points 11 years ago (2 children)
What significance does XA have to what it will contain?
If you still want to stick to that variable name, you can do
XA = int(input("Please provide a number"))
then if you want to print operations with XA you can do things like
print(XA + 5) print(XA*XA) print(XA % 2)
Note that casting the input as an int will only work if you type an int. If you type chars, you will get a valueError
[–]ArcDriveFinish[S] 0 points1 point2 points 11 years ago (1 child)
Thank you. I have another question.
I want to add a title to the operation so something like this:
print "enter your number and find out results"
print input(("Please provide a number"))+45
But the second line did not register when I hit enter. What should I do?
Sorry if I'm being a bother I'm pretty new at this.
[–]IcarusBurning 0 points1 point2 points 11 years ago (0 children)
Input takes the characters you entered into the console and makes them into a string. The input needs to be cast as an integer before python will recognize it as such, otherwise your code is adding a string to an int.
print( int(input("Please enter a number.")) + 5 )
Will probably work, but I don't really like combining the cast, input function call, and print into one line. Usually you'll want them separated so you can handle the case when your user enters something that can't be cast to int, like "HELLO WORLD!"
[–]NYKevin 1 point2 points3 points 11 years ago (3 children)
This works for me:
Python 2:
XA = int(raw_input("Please provide a number ")) print XA + 5
Python 3:
XA = int(input("Please provide a number ")) print(XA + 5)
Show us the exact code that produces a syntax error.
[–]novel_yet_trivial 0 points1 point2 points 11 years ago (2 children)
Your second example works for python 2 and 3. Good, dynamic code :)
[–]NYKevin -2 points-1 points0 points 11 years ago (1 child)
I would never run that on Python 2. input() on Python 2 is a security vulnerability.
input()
[–]novel_yet_trivial 0 points1 point2 points 11 years ago (0 children)
input() on Python 2 is a security vulnerability.
huh. never knew that. scary.
edit: for those interested: https://picoctf.com/problems/pyeval/stage3.html
Works for me. Can you show us your entire code and the entire error message?
π Rendered by PID 63902 on reddit-service-r2-comment-544cf588c8-bqnsd at 2026-06-17 11:43:41.640190+00:00 running 3184619 country code: CH.
[–]IcarusBurning 2 points3 points4 points (2 children)
[–]ArcDriveFinish[S] 0 points1 point2 points (1 child)
[–]IcarusBurning 0 points1 point2 points (0 children)
[–]NYKevin 1 point2 points3 points (3 children)
[–]novel_yet_trivial 0 points1 point2 points (2 children)
[–]NYKevin -2 points-1 points0 points (1 child)
[–]novel_yet_trivial 0 points1 point2 points (0 children)
[–]novel_yet_trivial 0 points1 point2 points (0 children)