100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4,6 TrustPilot
logo-home
Samenvatting

Summary Introduction to programming 2 ALL exam summaries

Beoordeling
-
Verkocht
-
Pagina's
16
Geüpload op
23-05-2023
Geschreven in
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.

Meer zien Lees minder

Voorbeeld van de inhoud

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

Documentinformatie

Geüpload op
23 mei 2023
Aantal pagina's
16
Geschreven in
2022/2023
Type
SAMENVATTING
€7,99
Krijg toegang tot het volledige document:

100% tevredenheidsgarantie
Direct beschikbaar na je betaling
Lees online óf als PDF
Geen vaste maandelijkse kosten

Maak kennis met de verkoper
Seller avatar
enk

Maak kennis met de verkoper

Seller avatar
enk Rijksuniversiteit Groningen
Bekijk profiel
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
10
Lid sinds
2 jaar
Aantal volgers
8
Documenten
0
Laatst verkocht
1 jaar geleden

0,0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Populaire documenten

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen