Subject Computer Science Python Programming

Question

1. Modify the program triangle.py from the textbook (Python Programming: An Introduction to Computer Science (Second Edition) by John M. Zelle, Ph.D. ) to draw a 5-sided polygon or pentagon from 5 points clicked on by the user.

2. Write a program that takes twenty mouse clicks from the user and draws a polygon whose corners, or vertices, are the clicked points.

3. Write a program that takes two mouse clicks from the user and draws rectangle whose corners include the two points clicked.

4. Write a program that asks the user for a list of prices of items purchased and prints out each price and the total, formatted nicely. Here is a sample run of the program:
Please enter the prices: 2.34, .99, 100, 81.05, 90

Your receipt:
2.34
0.99
100.00
81.05
90.00
----------------
Total: 274.38

5. Make a list of at least 5 different places that you like to visit (these should be places that you would like to visit and not identical to others' lists or it will be picked up by the cheat-checking programs).
Your program should print out the list regularly and vertically. For example,

['San Francisco', 'Christchurch ', 'Sydney ', 'Bangkok ', 'Copenhagen ']
S C S B C
a h y a o
n r d n p
i n g e
F s e k n
r t y o h
a c k a
n h g
c u e
i r n
s c
c h
o
Hint: if you have a list of strings, places, then places[0][i] refers to the ith character of the first word in your list. Start by printing out the first place name vertically, then add in the others.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#!/usr/bin/python

from graphics import *

def main():
    win = GraphWin("Draw a Pentagon")

    win.setCoords(0.0, 0.0, 10.0, 10.0)
    message = Text(Point(5, 0.5), "Click on five points")
    message.draw(win)
# Get and draw three vertices of triangle...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Get help from a qualified tutor
Live Chats