


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The solutions to test 2 for cosc 235, including examples of function definitions, line segment drawing, and a function to count negative numbers in a list. It also includes an example of exception handling.
Typology: Exams
1 / 4
This page cannot be seen from the preview
Don't miss anything!
9 module from graphics import * def moveTo(shape, newCenter): "Move the shape to point newCenter"
currCenter = shape.getCenter()
dx = newCenter.getX() - currCenter.getX() dy = newCenter.getY() - currCenter.getY()
shape.move(dx, dy)
print "Click once to move the circle, click again to close."
win = GraphWin() circ = Circle(Point(100,100), 25) circ.draw(win)
pt = win.getMouse() moveTo(circ, pt) win.getMouse() win.close()
from graphics import *
win = GraphWin("Line Segment", 600, 400)
Male Female Health Risk Based Solely on WHR 0.95 or below 0.80 or below Low Risk 0.96 to 1.0 0.81 to 0.85 Moderate Risk above 1.0 above 0.85 High Risk
from math import round def WHR(sex, waist, hips): """Computes the waist-to-hip ratio and returns an integer value that interprets the ratio: - 1 indicates low risk, 0 indicates moderate risk, and 1 indicates high risk. sex is either 'M' or 'F', indicating male or female. For example, WHR('M', 32, 36) returns - 1 (since the ratio is 0.89).""" (^1) round( x, n)—Return the floating point value x rounded to n digits after the decimal point. If n is omitted, it defaults to zero. The result is a floating point number. Values are rounded to the closest multiple of 10 to the power minus n; if two multiples are equally close, rounding is done away from 0 (so, for example, round(0.5) is 1.0 and round(‐0.5) is ‐1.0).