O'Reilly logo

Python Projects for Kids by Jessica Ingrassellino

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required