CS 235 Quiz #2: Page 1 of 5
COSC235 Fall 2007
Test #2
Please read each question carefully and be sure to give complete answers. Work quickly
and good luck!
1. (2 pt.) Print your name: ___________________________________________
2. (6 pts.) Given that x is 5 and y is 7, what is the value of x after each statement is
executed? Assume each part is independent of the preceding parts.
a) x /= y
b) x *= x + 2
c) x %= x – 4
3. (6 pts.) Write the equivalent while-loop for the following for-loop:
sum = 0
for i in range(1, 100, 3):
sum += i
4. (8 pts.) Write a while-loop that will
a) find the sum of the first 100 even numbers, i.e., 2 + 4 + 6 + … for 100 different
numbers.
b) count how many time a positive integer can be divided by two before it is zero.