This is simple. To convert a string to a number do this:
int(String)
after whatever you want to convert to an integer
Therefore, you would do:
num1 = raw_input("Enter a number: ")
num1 = int(num1)
but a faster way would be:
num1 = int(raw_input("Enter a number: "))
That second to last method can be used if you will use num1 as a string and a number (it will change to a number after int(num1)
Sorry just noticed another flaw. (Edited)
I was curious why you had to show the sum before the numbers were defined, and also wanted to tell you that you dont need the %d in the 3rd line and 3rd to last line, just go ahead and do
print "The summation of the numbers is", (num1+num2)
Another Flaw (Edit #2)
The last comment changed your print "The summation of the numbers is: %d " % (num1+num2) to return "The summation of the numbers is: %d " % (num1+num2)
but the person did not go over it with you. When you do return, you make the value of the command what the return value is. Let me give you an example.
def MultNumByTwo(num):
num = num * 2
return num
print MultNumByTwo(3)
This will print six, because MultNumByTwo takes num which I have made 3 and does num = num * 2 which gives it a new value of itself times two. Now, when I do return num, MultNumByTwo takes on the value of the number after return.
Now lets look at your code. When you do print "The summation of the numbers is: %d " % (num1+num2), the command has no value. It will just do what it was told which was add these two numbers. Therefore, you can only use it alone because it has become a command. You cannot use it in a print command.
If %d were to take commands in a print command anyways, it would be Again, the summation: %d but %d would be The summation of the numbers is: %d " % (num1+num2) and the entire command would print
Again, the summation: The summation of the numbers is: (num1+ num2)