Contents

  1. average2.py
  2. graphics_test.py
  3. rectangle.py
  4. rectangle_solution.py

average2.py 1/4

[
top][prev][next]
# Finds the average of two numbers
# by CS111 class

print("This program will calculate the average of two numbers")

# hardcode numbers
first = float(input("What is the first number? "))
second = float(input("What is the second number? "))

# add to the two numbers together 
total = first + second
# and divide by 2
average = total / 2

# display the result
print("Average of", first, "and", second, "=", average)

graphics_test.py 2/4

[
top][prev][next]
# Graphics Test Script
# by Sara Sprenkle

from graphics import *

win = GraphWin("My Circle", 200, 200)
point = Point(100,100)
c = Circle(point, 10)
c.draw(win)

c.setOutline(color_rgb(200, 0, 200))

# demonstrate what happens, outside of IDLE, if the line below is commented out.
win.getMouse()
win.close()

rectangle.py 3/4

[
top][prev][next]
# Draw a rectangle using the graphics API
# by CSCI111

# need this to be able to use code from the graphics.py file
from graphics import *



rectangle_solution.py 4/4

[
top][prev][next]
# Draw a rectangle using the graphics API
# by CSCI111

from graphics import *

win = GraphWin("Our Rectangle")

upperLeftPoint = Point(50, 50)
lowerRightPoint = Point(100, 100)
r = Rectangle(upperLeftPoint, lowerRightPoint)
# Alternative, not recommended approach: 
# r = Rectangle( Point(50, 50), Point(100, 100) )

# draw the rectangle, then wait for user to click the mouse
r.draw(win)
win.getMouse()

# move the rectangle to the right 10 px
r.move(10,0)

# get and display the rectangle's new coordinates
newUpperLeftPoint = r.getP1()
newLowerRightPoint = r.getP2()

print("coordinate of upper left point:", newUpperLeftPoint)
print("coordinate of lower right point:", newLowerRightPoint)

# How would I get just the X coordinate of the upper left point?

# pause, waiting for the user to click
win.getMouse()


Generated by GNU Enscript 1.6.6.