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 ...
Get Python Projects for Kids now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.