Your instructor may assign one or more of the following problems. Don’t feel that you must do all the problems; for the homeworks, you are only required to do those that are explicitly assigned via Moodle.
scores.py
that prompts
the user to enter the number of students and each student's name and
score, and finally displays the highest score and the second highest
score with their names. An example run follows:
NOTES:Please enter the number of students: 5 Please enter name and score number 1: John 37 Please enter name and score number 2: Sarah 39 Please enter name and score number 3: David 23 Please enter name and score number 4: Betsy 34 Please enter name and score number 5: Elizabeth 35 The highest score was 39 by Sarah. The second highest score was 37 by John.
split()
method as described in section 7.3 of the textbook.
Write a program called squares.py
that computes
and displays the squares of consecutive integers until the difference
between a square and the preceding one is greater than a user
specified value. An example run follows:
Note: No more than 10 squares should be printed on any line.Please enter the desired difference between squares: 10 1 4 9 16 25 36
Write a program called reverse.py
that prompts
the user to enter a positive integer (greater than zero), and then
displays the integer in reverse order. An example run is shown below:
Please enter a positive integer: 91827 91827 reversed is 72819
Consider using the %
operator to extract digits, and the /
operator to remove the extracted digit. For instance, to extract 4 from 234, use
234 % 10
, and then use 234 / 10
to remove the 4.
simple_stats.py
that
reads an unspecified number of integers, determines how many positive
and negative values have been read, and computes the sum and average
of the input values. Your program ends with the input 0 and should
not use the 0 in the count or average computations. Display the
average as a floating-point number. Here is an example run:
Enter as many int values as you'd like (the program exits if the input is 0): 1 2 -1 3 0 The number of positives is 3 The number of negatives is 1 The sum is 5 The average is 1.25
You may want to begin by computing the total of the numbers entered, and then add each additional statistic one at a time.
Write a turtle graphics program called
nautilus.py
that allows the user to draw multiply-sized versions of the golden
spiral, as shown to the right. You can find a discussion of the
dimensions of the spiral and its basis on the golden ratio (φ)
at golden spiral. For this
project, use the quarter-circle approximation of the true spiral.
The program should allow the user to specify/draw as many spirals as they would like, all starting at the same point in the bottom left as shown in the example on the right. Each spiral should be scaled to the size and rendered in the color specified by the user where the size is the radius of the main circle of the spiral. The example run has three spirals, each based upon the user-specified scale factors listed in the diagram. The scale factor specifies the radius of the first semi-circle drawn on the left. The color can be any simple color name accepted by the turtle’s color() method (e.g., “black”, “red”, ...).
You will likely need use additional features of the turtle’s circle() function, which you’ll find documented in Python’s Turtle graphics reference documentation. In particular, you’ll find the extent parameter useful for drawing partial circles. For each spiral, we suggest that you work from the outside in, repeatedly drawing segments of the spiral until the circle radius is small enough that no more detail can be seen. The samples on the right draw until the radius is reaches 1 pixel.
Write a turtle graphics program called
bounce.py
that drives a ball-shaped turtle around the canvas, bouncing off
walls when it hits them. See an example trace to the right in which
the ball/turtle started in the middle of the screen, headed off in a
north-easterly direction and bounced off both walls and the ceiling.
Note that the ball bounces "realistically" -- i.e., at the "opposite" angle it was at when it hit the wall.
For this program, let the ball start at the middle of the canvas with a random heading and let it go on moving forever. You are not required to draw the trace line.
You will likely need use additional turtle functions, which you’ll find documented in Python’s Turtle graphics reference documentation. In particular, you’ll find the following functions useful: xcor(), ycor(), heading(), setheading().
Algorithm:
Submit all appropriate files for grading, including code files, screen captures, supplemental files (e.g., image files), and text files. We will grade this exercise according to the following criteria:
If you work in teams for this homework assignment, be sure to submit all team members’ names in the code documentation.