Appendix D. Answers to Exercises

1. A Taste of Py

1.1 If you don’t already have Python 3 installed on your computer, do it now. Read Appendix B for the details for your computer system.

1.2 Start the Python 3 interactive interpreter. Again, details are in Appendix B. It should print a few lines about itself and then a single line starting with >>>. That’s your prompt to type Python commands.

1.3 Play with the interpreter a little. Use it like a calculator and type this: 8 * 9. Press the Enter key to see the result. Python should print 72.

1.4 Type the number 47 and press the Enter key. Did it print 47 for you on the next line?

1.5 Now type print(47) and press Enter. Did that also print 47 for you on the next line?

2. Data: Types, Values, Variables, and Names

2.1 Assign the integer value 99 to the variable prince, and print it.

2.2 What type is the value 5?

2.3 What type is the value 2.0?

2.4 What type is the expression 5 + 2.0?

3. Numbers

3.1 How many seconds are in an hour? Use the interactive interpreter as a calculator and multiply the number of seconds ...

Get Introducing Python, 2nd Edition 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.