#Oppgave 1 def storreEnnListe(liste, tall): storreEnn = [] for i in liste: if i > tall: storreEnn.append(i) return storreEnn #print(storreEnnListe([1,2,3,4,6,2,1,4], 3)) #Oppgave 2a def sumavListe(liste): total = 0 for tall in liste: total += tall return total #print(sumavListe([1,2,3])) #Oppgave 2b def gjennomsnitt(liste): return sumavListe(liste)/len(liste) #print(gjennomsnitt([1,2,3])) #Oppgave 3a def kvadrere(tall): return tall**2 #print(kvadrere(4)) #Oppgave 3b def kvadratetAvTre(tall1, tall2, tall3): return kvadratet(tall1) + kvadratet(tall2) + kvadratet(tall3) #print(kvadratetAvTre(1,2,3)) #Oppgave 3c def kvadratetavListe(liste): nyListe = [] for tall in liste: nyListe.append(kvadratet(tall)) return nyListe #print(kvadratetavListe([1,2,3])) #Oppgave 4a def nestStorst(liste): #Gaar utifra at listen inneholder minst 2 elementer storst = liste[0] neststorst = liste[0] for i in liste: if i > neststorst and i <= storst: neststorst = i elif i > storst: neststorst = storst storst = i return neststorst #print(nestStorst([1, 4, 8, 2, 5, 12, 24, 34, 23])) def sammenlignLister(liste1, liste2): return liste1 == liste2 #print(sammenlignLister([1,2,3], [1,2,3])) #print(sammenlignLister([1,2,3], [1,3,2]))