Exercises

  1. 1.1 (IPython Session) Using the techniques you learned in Section 1.10.1, execute the following expressions. Which, if any, produce a runtime error?

    1. 10 / 3

    2. 10 // 3

    3. 10 / 0

    4. 10 // 0

    5. 0 / 10

    6. 0 // 10

  2. 1.2 (IPython Session) Using the techniques you learned in Section 1.10.1, execute the following expressions. Which, if any, produce a runtime error?

    1. 10 / 3 + 7

    2. 10 // 3 + 7

    3. 10 / (3 + 7)

    4. 10 / 3 - 3

    5. 10 / (3 - 3)

    6. 10 // (3 - 3)

  3. 1.3 (Creating a Jupyter Notebook) Using the techniques you learned in Section 1.10.3, create a Jupyter Notebook containing cells for the previous exercise’s expressions and execute those expressions.

  4. 1.4 (Computer Organization) Fill in the blanks in each of the following statements:

    1. The logical unit that receives information from outside the computer for use by the computer is the      .

    2.       is a logical unit that sends information which has already been processed by the computer to various devices so that it may be used outside the computer.

    3.       and       are logical units of the computer that retain information.

    4.       is a logical unit of the computer that performs calculations.

    5.       is a logical unit of the computer that makes logical decisions.

    6.       is a logical unit of the computer that coordinates the activities of all the other logical units.

  5. 1.5 (Clock as an Object) Clocks are among the world’s most common objects. Discuss how each of the following terms and concepts applies to the notion of a clock: class, object, instantiation, instance variable, reuse, method, inheritance (consider, for example, an alarm clock), superclass, subclass.

  6. 1.6 (Gender Neutrality) Write down the steps of a manual procedure for processing a paragraph of text and replacing gender-specific words with gender-neutral ones. Assuming that you’ve been given a list of gender-specific words and their gender-neutral replacements (for example, replace “wife” or “husband” with “spouse,” replace “man” or “woman” with “person,” replace “daughter” or “son” with “child,” and so on), explain the procedure you’d use to read through a paragraph of text and manually perform these replacements. How might your procedure generate a strange term like “woperchild” and how might you modify your procedure to avoid this possibility? In Chapter 3, you’ll learn that a more formal computing term for “procedure” is “algorithm,” and that an algorithm specifies the steps to be performed and the order in which to perform them.

  7. 1.7 (Self-Driving Cars) Just a few years back the notion of driverless cars on our streets would have seemed impossible (in fact, our spell-checking software doesn’t recognize the word “driverless”). Many of the technologies you’ll study in this book are making self-driving cars possible. They’re already common in some areas.

    1. If you hailed a taxi and a driverless taxi stopped for you, would you get into the back seat? Would you feel comfortable telling it where you want to go and trusting that it would get you there? What kinds of safety measures would you want in place? What would you do if the car headed off in the wrong direction?

    2. What if two self-driving cars approached a one-lane bridge from opposite directions? What protocol should they go through to determine which car should proceed?

    3. If a police officer pulls over a speeding self-driving car in which you’re the only passenger, who—or what entity—should pay the ticket?

    4. What if you’re behind a car stopped at a red light, the light turns green and the car doesn’t move? You honk and nothing happens. You get out of your car and notice that there’s no driver. What would you do?

    5. One serious concern with self-driving vehicles is that they could potentially be hacked. Someone could set the speed high (or low), which could be dangerous. What if they redirect you to a destination other than what you want?

    6. Imagine other scenarios that self-driving cars will encounter.

  8. 1.8 (Research: Reproducibility) A crucial concept in data-science studies is reproducibility, which helps others (and you) reproduce your results. Research reproducibility and list the concepts used to create reproducible results in data-science studies. Research and discuss the part that Jupyter Notebooks play in reproducibility.

  9. 1.9 (Research: Artificial General Intelligence) One of the most ambitious goals in the field of AI is to achieve artificial general intelligence—the point at which machine intelligence would equal human intelligence. Research this intriguing topic. When is this forecast to happen? What are some key ethical issues this raises? Human intelligence seems to be stable over long periods. Powerful computers with artificial general intelligence could conceivably (and quickly) evolve intelligence far beyond that of humans. Research and discuss the issues this raises.

  10. 1.10 (Research: Intelligent Assistants) Many companies now offer computerized intelligent assistants, such as IBM Watson, Amazon Alexa, Apple Siri, Google Assistant and Microsoft Cortana. Research these and others and list uses that can improve people’s lives. Research privacy and ethics issues for intelligent assistants. Locate amusing intelligent-assistant anecdotes.

  11. 1.11 (Research: AI in Health Care) Research the rapidly growing field of AI big-data applications in health care. For example, suppose a diagnostic medical application had access to every x-ray that’s ever been taken and the associated diagnoses—that’s surely big data. As you’ll see in the “Deep Learning” chapter, computer-vision applications can work with this “labeled” data to learn to diagnose medical problems. Research deep learning in diagnostic medicine and describe some of its most significant accomplishments. What are some ethical issues of having machines instead of human doctors performing medical diagnoses? Would you trust a machine-generated diagnosis? Would you ask for a second opinion?

  12. 1.12 (Research: Big Data, AI and the Cloud—How Companies Use These Technologies) For a major organization of your choice, research how they may be using each of the following technologies that you’ll use in this book: Python, AI, big data, the cloud, mobile, natural language processing, speech recognition, speech synthesis, database, machine learning, deep learning, reinforcement learning, Hadoop, Spark, Internet of Things (IoT) and web services.

  13. 1.13 (Research: Raspberry Pi and the Internet of Things) It’s now possible to have a computer at the heart of just about any type of device and to connect those devices to the Internet. This has led to the Internet of Things (IoT), which already interconnects tens of billions of devices. The Raspberry Pi is an economical computer which is often at the heart of IoT devices. Research the Raspberry Pi and some of the many IoT applications in which it’s used.

  14. 1.14 (Research: The Ethics of Deep Fakes) Artificial-intelligence technologies are making it possible to create deep fakes—realistic fake videos of people that capture their appearance, voice, body motions and facial expressions. You can have them say and do whatever you specify. Research the ethics of deep fakes. What would happen if you turned on your TV and saw a deep-fake video of a prominent government official or newscaster reporting that a nuclear attack was about to happen? Research Orson Welles and his “War of the Worlds” radio broadcast of 1938, which created mass panic.

  15. 1.15 (Public-Key Cryptography) Cryptography is a crucial technology for privacy and security. Research Python’s cryptography capabilities. Research online for a simple explanation of how public-key cryptography is used to implement the BitCoin cryptocurrency.

  16. 1.16 (Blockchain: A World of Opportunity) Cryptocurrencies like Bitcoin and Ethereum are based on a technology called blockchain that has seen explosive growth over the last few years. Research blockchain’s origin, applications and how it came to be used as the basis for cryptocurrencies. Research other major applications of blockchain. Over the next many years there will be extraordinary opportunities for software developers who thoroughly understand blockchain applications development.

  17. 1.17 (OWASP Python Security Project) Building secure computer applications is a tremendous challenge. Many of the world’s largest companies, government agencies, and military organizations have had their systems compromised. The OWASP project is concerned with "hardening" computer systems and applications to resist attacks. Research OWASP and discuss their accomplishments and current challenges.

  18. 1.18 (IBM Watson) We discuss IBM’s Watson in Chapter 14. You’ll use its cognitive computing capabilities to quickly build some intriguing applications. IBM is partnering with tens of thousands of companies—including our publisher, Pearson Education—across a wide range of industries. Research some of Watson’s key accomplishments and the kinds of challenges IBM and its partners are addressing.

  19. 1.19 (Research: Mobile App Development with Python) Research the tools that are available for Python-based iOS and Android app development, such as BeeWare, Kivy, PyMob, Pythonista and others. Which of these are cross-platform? Mobile applications development is one of the fastest growing areas of software development, and it’s a great source of class projects, directed study projects, capstone exercise projects and even thesis projects. With cross-platform app-development tools, you’ll be able to write your own apps and deploy them on many app stores quickly.