Hemtal 1 Hemtal 1
A) Några Python-frågor A) Some Python questions
- Hur skriver man en for-slinga i Python? How do you write a for-loop in Python? Ge ett exempel! Give an example!
- Vad är parametrar? What are parameters?
- Vad är ett returvärde? What is a return value? Hur anropar man en funktion med returvärde? How do you call a function with return value?
- Vad är skillnaden mellan en funktion och en metod? What is the difference between a function and a method? Ge exempel på funktionsanrop och metodanrop! Give examples of function calls and method calls!
- Var används self? Where is self? Och till vad? And for what?
- Vilken funktion använder man för att konvertera ett tal till en sträng? What function is used to convert a number into a string?
- Vad är en modul, och hur importerar man den? What is a module, and how you import it? Ge exempel på några inbyggda moduler. Give examples of some built-in modules.
- Vad gör operatorn % (modulo) ? What does the% operator (modulo)?
B) GCD-algoritmen B) GCD algorithm
Hur fungerar gcd-algoritmen? How does the gcd-algorithm? Visa i en tabell vilka värden variablerna m
, n
, oldm
och oldn
antar om funktionen nedan anropas med gcd(30, 21)
. Show in a table which values the variables m
, n
, oldm
and oldn
adopt the following function is called with gcd(30, 21)
.
def gcd(m, n): def gcd (m, n):
while m % n != 0: While m% n: = 0:
oldm = m oldm = m
oldn = n oldn = n
m = oldn m = oldn
n = oldm % oldn n = oldm% oldn
return n return n
C) Stackar och köer C) Stacks and queues
Hur skiljer sig pop() i en stack från get() i en kö? How does pop () in a stack of get () in a queue? Rita detaljerade bilder som visar hur top, first, last
och next-
pekare ändras i varje sats om vi Draw detailed pictures showing the top, first, last
and next-
pointers in each rate change if we
- gör pop() på en stack med två element . do pop () on a stack of two elements.
- gör get() på en kö med två element . do get () on a waiting list of two elements.
Hemtalet tas med till övning 2 (8 eller 9 september) och rättas där! Den som gjort uppgiften ska skriva sitt namn och personnummer överst till höger på alla blad. Hemtalet taken to drill two (8 or 9 September) and corrected where anyone who has the task to write their names and numbers at the top right of any page.
Den som rättar ska skriva sitt namn och personnummer längst ner till vänster på första bladet, samt antal poäng och "G" eller "IG". Anyone who informs to write their names and numbers at the bottom left of the first leaf, and the number of points and the "G" or "IG".