Exam 1_Spring 2011

8 8 trace the following python code ie indicate the

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: s. 7. Write a Python graphics based program that requires the user to click on one point and then draws a 50 by 50 square with the clicked point in its lower right corner. 8 8. Trace the following Python code, i.e. indicate the state of the variables as they change and what output is printed to the screen: (a) f=8 s = 13 for i in range(2, 7) f, s = s, f + s print("f =", f, " s=", s) (b) n = 18 k=1 for c in range(5): n=n-c k=2*k+c print("n =", n, " k = ", k) 9. Draw the output that would be displayed in the program’s window if the following Python graphics based program were executed: from graphics import * def main(): win = GraphWin("Picture", 400, 400) win.setCoords(0,0,100,100) one two three four = = = = Point(10,10) Point(90,90) Point(one.getX(), two.getY()) Point(two.getX(), one.getY()) Rectangle(one,two).draw(win) Line(one,two).draw(win) Line(three,four).draw(win) win.getMouse() win.close() main() 10. Write a complete program that, using a loop, asks the user for the time and speed for 10 legs of a trip....
View Full Document

This document was uploaded on 03/24/2014 for the course CMP 230 at Lehman College.

Ask a homework question - tutors are online