100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

Summary Think Python2 Chapter 4

Rating
-
Sold
-
Pages
6
Uploaded on
07-10-2018
Written in
2018/2019

This is the summary for YOU, if you want to learn the basics of Python quickly. Not everyone has time to read a book of more than 200 pages. That's why I thought, why don't I make a short summary of it! This is a summary of chapter 4 of the book ThinkPython2 (with the exercises!). I can't summarize this book in a day ofcourse so I will keep uploading summaries of the chapters. So don't worry the rest of the chapters will come.

Show more Read less
Institution
Course








Whoops! We can’t load your doc right now. Try again or contact support.

Connected book

Written for

Institution
Study
Course

Document information

Summarized whole book?
No
Which chapters are summarized?
Chapter 4
Uploaded on
October 7, 2018
Number of pages
6
Written in
2018/2019
Type
Summary

Subjects

Content preview

Chapter 4 Case study: interface design
This chapter is a case study that demonstrates a process for designing functions that work
together. The turtle module is introduced, which allows you to create images. If you’re using
PythonAnywhere, you won’t be able to run the turtle examples(at least not in 2015).

If you don’t have Python installed yet, now is the time to do it. Instructions:
http://tinyurl.com/thinkpython2e. Code examples from this chapter: http://thinkpython2.com/code/ polygon.py.

4.1 The turtle module
To check if you have the turtle module, open the Python interpreter and type:
>>> import turtle
>>> bob = turtle.Turtle()

When you run this code, you should see a new window with a small arrow(the turtle).
Create a file named mypolygon.py and type:
import turtle
bob = turtle.Turtle()
print(bob)
turtle.mainloop()

The turtle module (with ’t’) provides a function called Turtle (with ’T’) that creates a Turtle object,
which we assign to the variable bob. Printing bob displays something like:
<turtle.Turtle object at 0xb7bfbf4c>

This means that bob refers to an object with type Turtle as defined in module turtle. mainloop tells
the window to wait for the user to do something. In this case the user has to just close the window.
Once you create a Turtle, you can call a method to move it around. A method is similar to a
function, but with different syntax. So to move the turtle forward:
bob.fd(100)

The method, fd, is associated with the turtle object bob. Calling a method is like making a request:
you are asking bob to move forward. The argument fd is a distance in pixels, so the actual size
depends on your display.

Other methods you can call on a Turtle are bk to move backward, lt left turn and rt right turn. lt and
rt are in degrees. Each Turtle is holding a pen which is down or up. When it’s down it leaves a trail
when it moves. The methods pu and pd stand for “pen up” and “pen down”. To draw a right angle,
write this (after creating bob and before calling mainloop):
bob.fd(100)
bob.lt(90)
bob.fd(100)
Now modify the program to draw a square!

4.2 Simple repetition
Chances are you wrote something like this:
bob.fd(100)
bob.lt(90)
bob.fd(100)
bob.lt(90)
bob.fd(100)
bob.lt(90)
bob.fd(100)
$3.62
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached


Also available in package deal

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Yuna429 Hogeschool Rotterdam
Follow You need to be logged in order to follow users or courses
Sold
185
Member since
8 year
Number of followers
130
Documents
38
Last sold
11 months ago

Ik probeer zo goed mogelijk samenvattingen te maken. Hierbij kijk ik naar de informatie die in je boek staat, de opgaven en ik kijk af en toe op internet.

4.2

92 reviews

5
48
4
23
3
14
2
1
1
6

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions