1.6 Summary

This chapter introduced the following fundamental building blocks of programming and Python:

  •    Using primitive types

  •    Using expressions

  •    Naming objects

  •    Using the modules and functions provided by Python

  •    Writing your own functions to extend the functionality provided by Python

  •    Using the for statement to repeat a block of code multiple times

In addition, the approach we followed to use the turtle to draw a circle illustrates an important problem-solving pattern that you will use many times as you progress through this text. That pattern can be summarized as the following Good Programming Practice:

We will continue to use these basic building blocks as we learn more about Python, and we will explore more tools that you can add to your toolbox. We have glossed over a few details on some of the ideas introduced in this chapter but will return to them later. As you delve into Python in more depth, always keep in mind this critical idea: Focus on problem solving while continually adding to your knowledge of programming and computer science.

Key Terms

  • abstraction

  • algorithm

  • assignment statement

  • attributes

  • block

  • camelCase

  • comment

  • complex number

  • computer science

  • constructor

  • define

  • dereferencing

  • dot operator

  • expression

  • floating-point number

  • function

  • generalization

  • instance

  • integer

  • keywords

  • libraries

  • loop variable

  • machine learning

  • method

  • module

  • name

  • object

  • parameter

  • program

  • programming language

  • prompt

  • Python

  • repetition

  • representation

  • sequence object

  • simplification

  • type

  • variable

Python Keywords

  • def

  • for

  • from

  • import

  • in

  • range

Programming Exercises

  1. 1.1     Using the drawSquare function, you can have the turtle create an interesting flowerlike shape by drawing many squares. Each square is drawn after turning the turtle by some number of degrees between each square. Write a function drawFlower that takes the number of squares to draw as a parameter (numSquares) and draws a flower by repeating the square numSquares times. You will need to figure out how far to turn the turtle based on numSquares.

  2. 1.2     Write a function to make the turtle draw a five-pointed star.

  3. 1.3     Write a function to make the turtle draw an n-pointed star when n is restricted to be odd.

  4. 1.4     Write a function to have the turtle draw a simple line drawing of anything you want.

  5. 1.5     The turtle understands two other functions: begin_fill() and end_fill(). When you call begin_fill, the turtle keeps track of its starting point, and all the lines it has drawn, until you call end_fill. When end_fill is called, the turtle fills in the space enclosed by the lines that the turtle has drawn. Use these new functions to draw a more interesting picture.

Design Credits: Calculator Icon made by Smashicons from www.flaticon.com

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.199.27