Submitted by: Submitted by cj622
Views: 202
Words: 414
Pages: 2
Category: Other Topics
Date Submitted: 02/09/2014 01:33 PM
Introduction to Computer Programming
Sample Final Exam
Student Information
Name: NetID:
I.
Evaluate the following expressions. Expression
3 * 4 + 16 / 2 5 ** 2 - 1 10 % 7 22 // 8 True and True not (True or False) False == False int(5.8) float(16) str(24) * 2
Return
II.
What will be printed after the following statements?
d = {'foo': 85, 'bar': 20, 'baz': 39, 'qux': 9} print(d['baz'])
1
Introduction to Computer Programming
Sample Final Exam
III.
Given the following string, what will each statement return?
s = 'May 15, 2013' s[2] s[4:6] s[-4] s[:10] len(s) 'A' in s s.count(',') s.find('15')
Return
IV.
Rewrite the following statement as a function with three parameters: length, width, and height. Give each of the parameters default values. Include a short doc string and a return statement in the function.
volume = length * width * height
2
Introduction to Computer Programming
Sample Final Exam
V.
Draw the output of the following Turtle graphics program in the space below.
import turtle window = turtle.Screen() draw = turtle.Turtle() n, l, a = 6, 100, 60 for s in range(n): draw.forward(l) draw.left(a) window.mainloop()
VI.
What will be the output of the following while-loop?
i = 72 while i > 9: print(i, end = ' ') i = i / 2
3
Introduction to Computer Programming
Sample Final Exam
VII.
This program creates a new text file with the information entered by the user. Fill in the missing line.
text = input('Enter text: ') name = input('Enter file name: ')
file.write(text) file.close()
VIII.
Assume you have a list called “high_temps” that contains 365 items representing the high temperature, in degrees, for each day of the past year. The list, high_temps, would look something like this: [84, 82, 94, 76, 90] – only longer. Write a program with high_temps that determines how many days had high temperatures of 90 degrees or above and print this answer to the screen. Keep in mind that the list...