Introduction to Programming using Python - Fall 2003



CSCI 151 Fall 2015 Test 3 PrepDate: November 6, 2015 Open book, open notes, NO CELLPHONES. YOU ARE NOT ALLOWED TO USE PUTTY FOR PART ITEST 3 consists of Two Parts Part I - 20 points – 1 short questions Part II - 80 points - 1 program writing question SAMPLE PART I Question 1Trace the following program and write the program output i = 0while (i<=10):print(“HELLO”)i = i +4print(“DONE”)SAMPLE PART I Question 2Trace the following program and write the program output sum = 0i = 2while (i<=10):sum = sum + ii = i + 3print(sum)SAMPLE PART I Question 3 Trace the following program and write the program output Explain, what this program is calculating num = 356793sum = 0i=1while (i<=6):k = num % 10sum = sum + knum = num / 10i = i + 1print(sum/6)SAMPLE PART I Question 4 Trace your program and write an output for the following input sequence: 12 345 6189 27 0Explain what this program is calculating.num = int(input(“enter number “))a= 0b= 0while(num!=0):k=num%10a=a+kb=b+1num = int(input(“enter number “)) if(b>0):c= a /bprint(a,b,c)else:print(“try again”)SAMLE Part II Q1. Student takes certain amount of courses during the academic year. Write a function that has one parameter - number of courses. The function reads final grade for each course, and returns the average final grade for the academic year. Write a program to test your function Q2. Write a function that accepts one parameter, positive integer, and finds and returns the average of its EVEN digits. If there are no even digits in the parameter, the function returns -1 Write a main function to test your function Q3. Write a function that doesn’t have any parameters. Function reads a sequence of non-zero integers. First zero value will terminate the input. The function finds and returns the number, sum, and average of the negative numbers. Pay attention on the special case of NO NEGATIVE numbers in your input. Write a program to test your function. Example: Input: 2 -5 6 7 -8 -9 0Output: there are 3 negative numbers, their sum is -22 and their average is -7.333333 ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download