100% de satisfacción garantizada Inmediatamente disponible después del pago Leer en línea o como PDF No estas atado a nada 4,6 TrustPilot
logo-home
Resumen

Summary Think Python2 Chapter 4

Puntuación
-
Vendido
-
Páginas
6
Subido en
07-10-2018
Escrito en
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.

Mostrar más Leer menos
Institución
Grado

Vista previa del contenido

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)

Libro relacionado

Escuela, estudio y materia

Institución
Estudio
Grado

Información del documento

¿Un libro?
No
¿Qué capítulos están resumidos?
Chapter 4
Subido en
7 de octubre de 2018
Número de páginas
6
Escrito en
2018/2019
Tipo
RESUMEN

Temas

$4.16
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Leer en línea o como PDF
No estas atado a nada


Documento también disponible en un lote

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
Yuna429 Hogeschool Rotterdam
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
185
Miembro desde
8 año
Número de seguidores
130
Documentos
38
Última venta
1 año hace

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 reseñas

5
48
4
23
3
14
2
1
1
6

Documentos populares

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes