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

Summary Introduction to programming 2 ALL exam summaries

Puntuación
-
Vendido
-
Páginas
16
Subido en
23-05-2023
Escrito en
2022/2023

The file contains everything important for the exam of Introduction to programming 2. The information is taken from the lecture slides as well as the books and these summaries helped me pass the exam. The file is divided into 7 parts, for each week of the block.

Mostrar más Leer menos
Institución
Grado

Vista previa del contenido

Week 1 Summary: Programming 2

* OO object is a sort of active data type that combines both data and operations
* Objects know stuff (they contain data), and they can do stuff (they have operations)
* Objects interact by sending each other messages (request for an object to
perform one of its operations)
* A graphics window is actually a collection of tiny points called pixels ("picture elements")




* Every object is an instance of some class, and the class describes the properties the instance will
have
* To create a new instance of a class, we use a special operation called a constructor
* A call to a constructor is an expression that creates a brand new object, the general form is as
follows:
<class-name> (<param1> , <param2> , . . . )
* The set of messages that an object responds to are called the methods of the object (methods are
functions that live inside the object), a method is invoked using dot-notation:

,<object> . <method-name> (<param1> , <param2> , . . . )
move (dx , dy) (moves the object dx units in the x direction and dy units in the y direction)
To move the point p to the right 10 units, we could use this statement:
p . move ( 10 , 0)
* First line creates a circle with a center located at the point (100, 100) and a radius of 30
* The second line creates a GraphWin
* The third line is a request for the Circle object circ to draw itself into the GraphWin object win
circ = Circle (Point ( 100 , 100) , 30)
win = GraphWin ( )
circ . draw (win)
* It is possible for two different variables to refer to exactly the same object; changes made to the
object through one variable will also be visible to the other
## Correct way to create two circles , using clone .
LeftEye = Circle (Point (80 , 50) , 5)
leftEye . setFill ('yellow')
leftEye . setOutline ('red')
rightEye = leftEye . clone ( ) # rightEye i s an exact copy of the left
rightEye . Move (20 , 0)
## Turtle example:
import turtle
win = turtle.Screen()
win.setup(width=512, height=512)
my_turtle = turtle.Turtle()
my_turtle.shape('turtle')
my_turtle.forward(50)
* Objects are instances of classes
* Objects are:
○ A collection of related information (data)
○ A set of operations to manipulate that information (methods)
* File handlers:
file_handler = open("test_file.txt", "r")
line = file_handler.readline()
data = file_handler.read()
file_handler.close()

, Week 2 Summary: Programming 2

* Control structures allow us to alter the sequential flow of our program
* Decision structures are a type of control structure that allow a program to execute different
sequences of instructions for different cases allowing the program to select an appropriate
course of action
* Simple if-then structures are called: one-way decisions
* Two-way decisions are if-else statements
* Multi-way decisions: nesting and adding an if-then statement inside another
* A better solution is to use if-elif-else
* For implements a definite loop: you know exactly how many iterations should be performed
*While implements an indefinite loop: the loop must be performed as long as a certain condition
applies (condition is a Boolean expression, just like in if statements)
* <filevar> = open(<name>, <mode>)
‘name’ is a string with the actual file name on the disk
‘mode’ is either ‘r’ or ‘w’ (read or write)
* infile = open("document.txt", "r")
outfile = open("document.txt", "w")
* <file>.read() – returns the entire remaining contents of the file as a single (possibly large, multi-
line) string
* <file>.readline() – returns the next line of the file. This is all text up to and including the next
newline character
* <file>.readlines() – returns a list of the remaining lines in the file. Each list item is a single line
including the newline characters
* If you open an existing file for writing, you delete the file’s contents
outfile = open("mydata.out", "w")
print(<expressions>, file=outfile)
* Standard Input/Output - allow program to read-from/write-to the console (without opening a
file)
* Using standard input/output or a file depends on program requirements
* Special file-handles that exist in the sys module:
- standard output: sys.stdout
- standard error: sys.stderr
- standard input: sys.stdin

Escuela, estudio y materia

Institución
Estudio
Grado

Información del documento

Subido en
23 de mayo de 2023
Número de páginas
16
Escrito en
2022/2023
Tipo
RESUMEN

Temas

$9.47
Accede al documento completo:

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

Conoce al vendedor
Seller avatar
enk

Conoce al vendedor

Seller avatar
enk Rijksuniversiteit Groningen
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
10
Miembro desde
2 año
Número de seguidores
8
Documentos
0
Última venta
1 año hace

0.0

0 reseñas

5
0
4
0
3
0
2
0
1
0

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