Operations on two numbers
We are going to use the raw_input()
function that we learned about in Chapter 2, Variables, Functions, and Users. Recall that from this chapter, we cannot perform addition on two strings. In fact, we cannot perform any kind of mathematical operations on strings.
The following code asks for user input and stores the input in the computer as strings. Type the following code in your Python shell to take a look at the results:
def addition(): first = raw_input('I will add two numbers. Enter the first number') second = raw_input('Now enter the second number.') print(first + second)
What happens when you call the addition()
function? If you call the addition()
function, you will see that the addition has NOT happened. This program just prints the two numbers together, side by side, in the order that they were entered by the user:
While putting information side by side is useful to combine words into a phrase or sentence, it is not very helpful...