# (Microsoft PowerPoint - tenta20061028_l\366sningar.ppt)

```Uppgift 1
• Parametrar
Tental&ouml;sning
– text
–m
• Argument
2006-10-28
–5
def centrera(text, vidd):
spaces=(vidd-len(text))/2
return (' '*spaces)+text+(' '*(vidd-len(text)-spaces))
• x=-1
• y=29
1
def concat(lista):
utlista=[]
for i in lista:
utlista=utlista+i
return utlista
• a
– flyttal representerar reella tal
– heltal representerar just heltal
• b
– dictionaries kan indexeras med godtycklig muterbar typ
• c
– en felutskrift (typfel)
• d
– True
• e
– ett bibliotek med f&auml;rdiga funktioner
• [2, 2, 3, 4, 5, 6, 7]
• om y&lt;x och z&lt;y blir det fel
– y ist&auml;llet f&ouml;r z
• om z&lt;x och y&lt;z blir det fel
– z ist&auml;llet f&ouml;r y
2
def minst(x,y,z):
min=x
if y&lt;min:
if y&lt;z:
return y
if z&lt;min:
return z
return x
def mean(x):
acc = 0.0
try:
for i in range(len(x)):
acc = acc + x[i]
except TypeError:
raise TypeError, ’Argument must be list of numbers’
try:
mean = acc/len(x)
except ZeroDivisionError:
raise TypeError, ’Empty list, Argument must be list
of numbers’
return mean
def mean(x):
acc = 0.0
for i in range(len(x)):
acc = acc + x[i]
mean = acc/len(x)
return mean
def expand(str, val):
pos=str.find('%s')
if pos==-1:
return str
return
str[0:pos]+val+str[pos+2:]
3