Docsity

CS 1301 Exam 2 - Spring 2009, Exams of Computer Science

Toggle sidebar
bg1
Your Name: _______________________________ Your TA's Name: ________________________
1 / 8
CS 1301 CS1 with Robots Spring 2009 โ€“ Exam 2
You have 50 minutes for this exam.
Problem Points Earned Possible Points
1. Vocabulary Matching 15
2. N_Lines 3
3. Robot Directions 10
4. Fill in the Blank 5
5. Expression Evaluation 20
6. Change Letter 10
7. Change Value 5
8. Return Smallest 6
9. My Length 15
10. Reverse List 15
Extra Credit (4 possible)
Total Score 104
pf3
pf4
pf5
pf8

Partial preview of the text

Download CS 1301 Exam 2 - Spring 2009 and more Exams Computer Science in PDF only on Docsity!

You have 50 minutes for this exam.

 - 1 / 
  • CS 1301 CS1 with Robots Spring 2009 โ€“ Exam
      1. Vocabulary Matching Problem Points Earned Possible Points
      1. N_Lines
      1. Robot Directions
      1. Fill in the Blank
      1. Expression Evaluation
      1. Change Letter
      1. Change Value
      1. Return Smallest
      1. My Length
      1. Reverse List
    • Total Score Extra Credit (4 possible)

1. Vocabulary Matching: (15 points)

Write the number from the correct definition in the blank next to each term on the left:

___compound data type

___aliases ___sequence ___recursion ___iteration ___slice ___traverse ___nested list ___clone ___immutable type ___mutable ___increment ___semantic error ___decrement ___element

  1. A part of a string specified by a range of indices.
  2. A compound data type whose elements can be assigned new values.
  3. The process of calling the function that is currently executing.
  4. Repeated execution of a set of statements using either a recursive function call or a loop.
  5. Multiple variables that contain references to the same object.
  6. To move through the elements of a sequence, such as a list, performing a similar operation on each.
  7. Any of the data types that consist of an ordered set of elements, with each element identified by an index.
  8. A list that is an element of another list.
  9. To increase the value of a variable by one.
  10. To decrease the value of a variable by one.
  11. One of the values in a list (or other sequence). The bracket operator selects an __________ of a list.
  12. A type in which the elements cannot be modified. Assignments to elements or slices of these types cause an error.
  13. To create a new object that has the same value as an existing object.
  14. A data type in which the values are made up of components, or elements, that are themselves values.
  15. Does not display red text to the console or interrupt the program from running.

4. Fill in the blank ( 5 points)

In python, the = operator performs _____________________ while the == operator performs _______________________. Python has several compound data types that we have learned about. A _________ can be used to store a sequence of characters, while a _________ can store a sequence of any type of data (but is immutable). A ________ can also store any type of data, and allows you to change elements within it.

5. Python Expression Evaluation (20 points)

For this question, assume the following statements have already been entered and

interpreted:

a = [ 5, 10, 15, True, ["Cherry", "Apple","Plum"], 56, [4, 5, 6], 84 ] b = a c = a[0:4] d = a[4] d[2] = "Peach"

Pretend that you are the Python Interpreter (IDLE window). What do you print or return

when each of the following statements are entered?

Example: a[0] Result: 5

Example: a[1:4] Result: _ [ 10, 15, True ]_

1. a[6][0] Result:________

2. d Result:________

3. c Result: ________

4. a[4][2] Result: ________

5. b[:2] Result: ________

6. b[-2] Result: ________

7. c[-2] Result: ________

8. print "Pumpkin %.3f" %3.1459 Result: ________

9. (5 > 10) or (5 > 3) Result: ________

10. 34 % 10 Result: ________

6. Write Code โ€“ Change Letter ( 10 points)

Write a function changeLetter(aString, index, newLetter) that will replace the letter

stored at index in aString with the contents of newLetter and return the new string

without modifying the original string! For example, changeLetter("Python is great!",

10, "G") will return the string "Python is Great!"

7. Write Code โ€“ Change Value (5 points)

Write a function changeValue(aList, index, newValue) that will replace the element

stored at index in aList with the contents of newValue. It should NOT return the list. For

example after the following commands:

a = [5, True,"Test",10]

changeValue( a, 3, "Hi!")

The list a will be [5, True,"Test","Hi!"]

9. Write Code - myLength (15 points)

Write a function myLength (sequence) that returns the length of the sequence. (In

essence, you are re-implementing the system's len(x) function.) Obviously, you may not

use the len(x) or any other system functions to do the work for you.

myLength(โ€œtestโ€ ) #evaluates to 4

myLength([1,2,3]) #evaluates to 3

myLength( (2,4,8,2) ) #evaluates to 4

10. Write Code โ€“ Reverse List (15 points)

Write a function reverseList(aList) that will return a reversed copy of aList. For

example, after the following:

a = [ 5, 10, True, "Hi!"]

b = reverseList(a)

The list b = ["Hi!", True, 10, 5], while a = [5, 10, True, "Hi!"].

Extra Credit (1 point each)

What function do you use to get the Battery voltage? _____________________

What is the decimal representation of the binary number { 100101} 2? ____________

What is the hexadecimal representation of the decimal number {62} 10? _____________

What does CSS stand for? C__________ S________________ S_______________