This assignment will involve writing several Python functions. You should save all of your functions in a single Python module named lastnameFuncs
(where lastname
is your last name). The module should have a comment block at the top, containing the file name, your name, the date, and a brief description. Each function should also have a doc string that describes its behavior.
Note: this work must be entirely your own, with no outside assistance other than the instructor.
For the first part of this assignment, you will rewrite your relative time code from HW2 in function form. In particular, you will repackage your code into the following functions:
observed_time
: takes two inputs, a distance (in light years) and a velocity (in percentage of light speed), and returns the observed time for traveling that distance at that speed. For example, observed_time(309, 50)
would return 618.0.
relative_time
: takes two inputs, a distance (in light years) and a velocity (in percentage of light speed), and returns the relative time for traveling that distance at that speed. For example, relative_time(309, 50)
would return 267.60184976939155.
time_table
: takes two inputs, a distance (in light years) and a sequence of velocities (percentages of light speed), and prints a table of the observed and relative times for traveling that distance at those velocities. As was the case in HW2, the times should appear in columns with headings, and should be rounded to the nearest tenth of a year. For example, time_table(309, [10, 25, 50, 75, 90, 99])
would produce the following output:
Note: this function must call the observed_time
and relative_time
functions.
In honor of the Creighton Volleyball team being in the top 10, you will develop a series of Python functions for simulating volleyball games and collecting statistics on competitive balance. These functions will have many similarities to the Pig simulation functions we wrote in class (see control.pytxt for the code).
Assume that the two teams in a volleyball game are each given a power ranking: an integer between 1 and 100. The higher the power ranking, the more likely that team is to win a particular point. For example, if team 1 and team 2 have identical power rankings, say 60 and 60, each is equally likely to win a given point. However, if team 1 has a power ranking of 80 and team 2 has a power ranking of 40, then team 1 is twice as likely to win a given point. The following Python function can be used to simulate a single point in a volleyball game.
Note that a team has to win a game by at least two points. You will need to think carefully how to address this in your function.
The components of the return pair can be accessed individually using a variant of an assignment statement:
team1/team2 rankings | expected % of points won by team 1 | actual % of games won by team 1 |
---|---|---|
50/50 | 50.0% | |
55/45 | 55.0% | |
75/50 | 60.0% | |
80/40 | 66.7% | |
60/20 | 75.0% | |
80/20 | 80.0% | |
90/10 | 90.0% |
team1/team2 rankings | expected % of points won by team 1 | actual % of games won by team 1 |
---|---|---|
50/50 | 50.0% | |
55/45 | 55.0% | |
75/50 | 60.0% | |
80/40 | 66.7% | |
60/20 | 75.0% | |
80/20 | 80.0% | |
90/10 | 90.0% |