Description
Learning objectives:
- Accumulations
- Use conditional control structures.
Download: Lab9.py from Oaks.
- Starter?
To earn a starting position on the wrestling team, a player must meet at least one of the following conditions:
- His weight is equal to or more than 150 and less than 160, and he has won 5 or more matches
- His weight is more than 199, or his number of wins is greater than 20
Write a function starter() that asks for input of two values, weight which is a float representing a player’s weight, and numWins which is an int representing the number of wins the player has had. The program should print out an appropriate message stating whether or not the individual should start. Add code to main() to test your function.
- Checksum
Most published books have an associated ISBN, a number printed on the back cover of the book and used to uniquely identify the book. The last digit, called the “checksum”, is a check digit used to catch typing errors when the number is entered.
There are many ways to calculate a checksum depending on its use. With 10 digit ISBNs, the method is to take each digit of the number and multiply it by its positional value. (The leftmost digit is considered position 10 and the rightmost digit is considered position 1.) The sum of these products mod 11 should be 0. The rightmost digit, called the “checksum”, helps ensure that the preceding nine digits are correct.
Example: Consider the ISBN number
0072946520 = 0*10 + 0*9 + 7*8 + 2*7 + 9*6 + 4*5 + 6*4 + 5*3 + 2*2 + 0*1 = 187
Write a function isValid(isbn)à Boolean that accepts as a parameter a string representing an ISBN and returns a Boolean indicating whether that string is a valid ISBN. The program should then calculate the sum of the digits using the formula mentioned above and determine if the ISBN is a valid number. Add code to main() to test your function.
- Circles
A function called circleOverlap() is provided which allows the user to make two clicks to draw one circle. Add code to draw a second circle. Remember the Euclidean distance formula to determine the distance between two points:
After drawing the two circles, display a message in the graphics window that outputs whether the circles overlap. If they overlap, display “The circles overlap.” Otherwise, display “The circles do not overlap.” For our purposes they “overlap” if they touch at a single point or more.
Ask the user to click to end the program, and be sure to close the window at the end. Add code to main() to test your function.
- Leap Year
There are approximately 365¼ days in a year. So that the calendar stays accurate, an extra day is added every four years.
A year is a leap year if it is evenly divisible by 4. However, that adds too many days, so a year is not a leap year if it is evenly divisible by 100. But then the year is a bit too short, so a year that is evenly divisible by 400 is a leap year. (So February 29, 2000, was a very special day. There won’t be another leap day in a century year until 2400.)
Write leapYear(year) à Boolean that accepts a numeric value representing a year and returns a Boolean indicating whether that year is a leap year.
Add code to main() to test your function. Output messages like:
2000 is a leap year
2100 is not a leap year
Upload the file Lab9.py to both student accounts.