Download Test 3 Preparation

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CSCI 151 Fall 2013 TEST 3 PREP



Date: November 8, 2013
Open book, open notes, NO CELLPHONES. YOU ARE NOT ALLOWED TO USE PUTTY FOR
PART I
TEST 1 consists of Two Parts
o Part I - 60 points – 2 short questions
o Part II - 40 points - 1 program writing question
SAMPLE PART I Question 1
Trace the following program and write the program output
i=0
while (i<=10):
print(“HELLO”)
i = i +4
print(“DONE”)
SAMPLE PART I Question 2
Trace the following program and write the program output
sum = 0
i=2
while (i<=10):
sum = sum + i
i=i+3
print(sum)
SAMPLE PART I Question 3
a. Trace the following program and write the program output
b. Explain, what this program is calculating
num = 356793
sum = 0
i=1
while (i<=6):
k = num % 10
sum = sum + k
num = num / 10
i=i+1
print(sum/6)
SAMPLE PART I Question 4
a. Trace your program and write an output for the following input sequence:
12 345 6189 27 0
b. Explain what this program is calculating.
num = int(input(“enter number “))
a= 0
b= 0
while(num!=0):
k=num%10
a=a+k
b=b+1
num = int(input(“enter number “))
if(b>0):
c= a /b
print(a,b,c)
else:
print(“try again”)
SAMLE Part II
Q1. Student takes certain amount of courses during the academic year. Write a program that reads
number of courses and final grade for each course, and finds the average final grade for the
academic year. Use TOP-DOWN design.
Q2. Write a function that accepts one parameter, which is 10-digit integer, and finds and prints
the average of its EVEN digits. If there are no even digits in the parameter, the function prints an
appropriate message. Write a main function to test your function
Q3. Write a program that reads a sequence of non-zero integers. First zero value will terminate
the input. The program finds amount, sum, and average of the negative numbers.
Example: Input: 2 -5 6 7 -8 -9 0
Output: there are 3 negative numbers, their sum is -22 and their average is -7.333333
Related documents