



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




__ 2 _Boolean expression __ 5 _Variable __ 8 _Global Variable __ 3 _Runtime error _ 14 _Semantic error __ 1 _Program __ 8 _Iteration _ 15 _Compound data type __ 9 _Mutable _ 12 _Aliases _ 13 _Immutable type _ 11 _Syntax error __ 4 _Block __ 7 _Recursion _ 10 _Function __ 6 _Integer
a= [23, 22, [431, 445, False], 12, [āChocolateā, āVanillaā, āStrawberryā], 33, True] b= a c= a[0:3] d= a[4] d[2] = āSwirlā e= a[2] e[2]= True
What is printed or returned when each of the following statements are entered?
def insertionSort(aList): length = len(aList) beginUnsorted = if (length<2): return if(aList[beginunsorted]<aList[beginUnsorted-1]: (aList[beginUnsorted-1], aList[beginUnsorted]) = (aList[beginUnsorted], aList[beginUnsorted-1])
print aList
insertionSort(aList)
6. Write Code (15 pts) Using file I/O write a function called longerSong that opens up an existing file containing 3 lines of notes and then adds an additional line of notes and then plays the song.
def longerSong(): file1 = open(āsong.txtā, āwā) file1.write(ā\n 800, 1ā) file1.close()
file1 = open(āsong.txtā, ārā) beep(file.readline())) beep(file.readline())) beep(file.readline())) beep(file.readline())) file.close()