Programming and Problem Solving - Test 2 - Spring 2007 | COSC 235, Quizzes of Computer Science

Material Type: Quiz; Professor: Sloan; Class: Programming & Problem Solving; Subject: Computer Science; University: Wofford College; Term: Spring 2007;

Typology: Quizzes

Pre 2010

Uploaded on 08/16/2009

koofers-user-c3w
koofers-user-c3w 🇺🇸

4

(1)

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 235A Quiz #1: Page 1 of 4
COSC235 Spring 2007
Test #2
Please read each question carefully and be sure to give complete answers. Work quickly
and good luck!
1. (1 pt.) Print your name: ___________________________________________
2. (9 pts.) Given that x10 is 10 and y3 is 3, what is the value of x10 after each statement
is executed? Assume each part is independent of the preceding parts.
a) x10 %= y3
b) x10 += 2 + x10 / y3
c) x10 -= x10 * 3 – 4
3. (6 pts.) Write an update operator that will
a) add y to x. E.g., if x is 2 and y is 3, x becomes 5.
b) triple the value of x and add five to it. E.g., if x is 10, then x becomes 35.
4. (9 pts.) For each of the following, give the result or explain why the action is illegal:
a) a = 1, 2, 3
b) b = (1, 2, 3)
b[3 ] = 4
c) (a, b) = 5
5. (4 pts.) What command do you execute to load the graphics library in Python?
pf3
pf4

Partial preview of the text

Download Programming and Problem Solving - Test 2 - Spring 2007 | COSC 235 and more Quizzes Computer Science in PDF only on Docsity!

COSC 235 Spring 2007

Test

Please read each question carefully and be sure to give complete answers. Work quickly and good luck!

  1. (1 pt.) Print your name: ___________________________________________
  2. (9 pts.) Given that x10 is 10 and y3 is 3, what is the value of x10 after each statement is executed? Assume each part is independent of the preceding parts. a) x10 %= y b) x10 += 2 + x10 / y c) x10 - = x10 * 3 – 4
  3. (6 pts.) Write an update operator that will a) add y to x. E.g., if x is 2 and y is 3 , x becomes 5. b) triple the value of x and add five to it. E.g., if x is 10 , then x becomes 35.
  4. (9 pts.) For each of the following, give the result or explain why the action is illegal: a) a = 1, 2, 3 b) b = (1, 2, 3) b[3 ] = 4 c) (a, b) = 5
  5. (4 pts.) What command do you execute to load the graphics library in Python?
  1. (16 pts.) Assume that the file data.txt contains the following four lines: How Now Brown Cow? After opening the file and associating it with the variable infile, what will be in the variable data after of each of the following has completely executed? Assume that each part begins with a newly opened file, i.e., is independent of the preceding parts. a) data = infile.read() b) data = infile.readlines() c) data = infile.readline() d) for line in infile: data = line
  2. (12 pts.) Tell whether each of the following will succeed or fail if x is 2 , y is 3 , gender is “female”, and test is False. a) y <= x or test b) x < y and x + 2 > y c) test or not test d) gender != “male” and not test and x != y or test
  1. (7 pts.) Write a Boolean function prezCk() that takes three parameters, a string giving nationality, an integer giving age, and a Boolean variable that is True if the individual is a naturalized citizen and False otherwise. The function should return True or False depending of whether the person is eligible to run for president. For example, prezCk(“United States”, 35, False) would return True.
  2. (8 pts.) Write a function class() that takes a nonnegative integer argument hours and returns “freshman” if hours is between 0 and 29, “sophomore” if hours is between 30 and 59, “junior” if hours is between 60 and 89, and “senior” if hours is 90 or more. E.g., class(45) returns “sophomore”.
  3. (8 pts) Write a function head() that takes a file name and a count as arguments and displays the first count lines in the specified file. For example, the call head(“data.txt”, 2) would display the first two line in the file data.txt. Pledged: ________________________________________________________________