Docsity

Introduction to Computing - Final Exam Practice Problems | CS 1301, Exams of Computer Science

Toggle sidebar
bg1


YourName_________________________________________________1/6

CS1301withRobotsFall2007ī˜ ā€“ī˜ MockFinalExam

1.VocabularyMatching(15pts)

__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

1.Asequenceofinstructionsthatspecifiestoacomputer
actionsandcomputationstobeperformed.
2.Anexpressionthatiseithertrueorfalse.
3.Anerrorthatdoesnotoccuruntiltheprogramhasstartedto
executebutthatpreventstheprogramfromcontinuing.
4.Agroupofconsecutivestatementswiththesame
indentation.
5.Anamethatreferstoavalue.
6.APythondatatypethatholdspositiveandnegativewhole
numbers.
7.Theprocessofcallingthefunctionthatiscurrently
executing.
8.Repeatedexecutionofasetofstatementsusingeithera
recursivefunctioncalloraloop.
9.Acompounddatatypeswhoseelementscanbeassignednew
values.
10.Anamedsequenceofstatementsthatperformssomeuseful
operation.Theymayormaynottakeparametersandmayor
maynotproducearesult.
11.Anerrorinaprogramthatmakesitimpossibletoparse(and
thereforeimpossibletointerpret).
12.Multiplevariablesthatcontainreferencestothesameobject.
13.Atypeinwhichtheelementscannotbemodified.
pf3
pf4
pf5

Partial preview of the text

Download Introduction to Computing - Final Exam Practice Problems | CS 1301 and more Exams Computer Science in PDF only on Docsity!

CS 1301 with Robots Fall 2007 – Mock Final Exam

  1. Vocabulary Matching (15pts)

__ 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

  1. A sequence of instructions that specifies to a computer actions and computations to be performed.
  2. An expression that is either true or false.
  3. An error that does not occur until the program has started to execute but that prevents the program from continuing.
  4. A group of consecutive statements with the same indentation.
  5. A name that refers to a value.
  6. A Python data type that holds positive and negative whole numbers.
  7. The process of calling the function that is currently executing.
  8. Repeated execution of a set of statements using either a recursive function call or a loop.
  9. A compound data types whose elements can be assigned new values.
  10. A named sequence of statements that performs some useful operation. They may or may not take parameters and may or may not produce a result.
  11. An error in a program that makes it impossible to parse (and therefore impossible to interpret).
  12. Multiple variables that contain references to the same object.
  13. A type in which the elements cannot be modified.
  1. An error in a program that makes it do something other than what the programmer intended.
  2. A data type in which the values are made up of components, or elements, that are themselves values.
  3. Python Expression Evaluations (15pts) For these questions assume the following statements have been entered and interpreted:

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?

  1. c Result : _[23, 22, [431, 445, True], 12]____
  2. d Result : [ā€œChocolateā€, ā€œVanillaā€, ā€œSwirlā€]_
  3. c[3] Result : _[12]______________
  4. a[2][1] Result : _[445]___________________
  5. e Result : _[431, 445, True]___________________
  6. a[6] Result : _[True]___________________
  7. a[3:5] Result : [12, [ā€œChocolateā€, ā€œVanillaā€, ā€œSwirlā€], 33]
  8. a[4][0] Result : _[ā€œChocolateā€]_______________
  9. d[-1] Result : _[ā€œVanillaā€]__________________
  10. c[-2] Result : ______[22]___________
  1. Sorting (15 pts ) Write an insertion code that will sort the following list: aList = [101, 33, 65, -5, 122, 65, 89]

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()