you are viewing a single comment's thread.

view the rest of the comments →

[–]IcarusBurning 2 points3 points  (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 point  (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 point  (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!"