# Initialize Otter
import otter
grader = otter.Notebook("hw6-branching.ipynb")

Homework 6#

This assignment includes three problems on the topic of branching.

Entering Your Information for Credit#

To receive credit for assignments it is important we can identify your work from others. To do this we will ask you to enter your information in the following code block.

Before you begin#

Run the block of code at the top of the notebook that imports and sets up the autograder. This will allow you to check your work.

# Please provide your first name, last name, Drexel ID, and Drexel email. Make sure these are provided as strings. "STRINGS ARE TEXT ENCLOSED IN QUOTATION MARKS."

# In the assignments you will see sections of code that you need to fill in that are marked with ... (three dots). Replace the ... with your code.
first_name = ...
last_name = ...
drexel_id = ...
drexel_email = ...
grader.check("q0-Checking-Your-Name")

Question 1: Grade Calculator

Your task is to write a funciton accepts an integer score and returns a string of the letter grade that score corresponds to. The mapping of score ranges to letter grades is:

Score

Letter Grade

95-100

A+

90-94

A

80-89

B+

70-79

B

60-69

C+

50-59

C

0-49

F

(Important note: This is just an example, not the letter grade mapping for this course.)

Write python code to do the following:

  • Define a function called letter_grade which accepts one input argument, an integer score s

  • Implement your function so that it returns the proper letter grade for an input score

  • You may assume the input s is an integer, but if s is outside the bounds \([0, 100]\), your function should return the message: "invalid score"

Your code replaces the prompt: ...

...
grader.check("q1-grade-calculator")

Question 2: Leap Year

A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are:

  1. The year must be divisible by 4

  2. If the year is a century year (1700, 1800, etc.), the year must be evenly divisible by 400

Some examples:

  • 1600, 1712, and 2016 are all leap years

  • 2002 is not a leap year (not divisible by 4)

  • 1900 is not a leap year (1900 is a century year not divisible by 400)

Your task is to code a function that identifies whether or not a year is a leap year.

Write python code to do the following:

  • Define a function called is_leap_year which accepts one input argument, an integer year y

  • Implement your function so that it returns True if the the year y is a leap year and otherwise returns False

Your code replaces the prompt: ...

...
grader.check("q2-leap-year")

Question 3: Seasons

The date ranges for the seasons are as follows:

Season

Date Range

spring

March 20 - June 20

summer

June 21 - September 21

autumn

September 22 - December 20

winter

December 21 - March 19

Your task is to write a function that takes in a date and returns the season that the date falls in.

Write python code to do the following:

  • Define a function called get_season that takes as input arguments a string m and an integer d

  • The function should determine the season the date given by month m and day d

    • For example, if m = "march" and d = 27, the function should return β€œspring”

  • You must check that m and d form a valid date. If not, return β€œinvalid”

You may assume the month m is in all lowercase

Your code replaces the prompt: ...

...
grader.check("q3-seasons")

Submitting Your Assignment#

To submit your assignment please use the following link the assignment on GitHub classroom.

Use this link to navigate to the assignment on GitHub classroom.

If you need further instructions on submitting your assignment please look at Lab 1.

Viewing your score#

It is your responsibility to ensure that your grade report shows correctly. We can only provide corrections to grades if a grading error is determined. If you do not receive a grade report your grade has not been recorded. It is your responsibility either resubmit the assignment correctly or contact the instructors before the assignment due date.

Each .ipynb file you have uploaded will have a file with the name of your file + Grade_Report.md. You can view this file by clicking on the file name. This will show you the results of the autograder.

We have both public and hidden tests. You will be able to see the score of both tests, but not the specific details of why the test passed or failed.

Note

In python and particularly jupyter notebooks it is common that during testing you run cells in a different order, or run cells and modify them. This can cause there to be local variables needed for your solution that would not be recreated on running your code again from scratch. Your assignment will be graded based on running your code from scratch. This means before you submit your assignment you should restart the kernel and run all cells. You can do this by clicking Kernel and selecting Restart and Run All. If you code does not run as expected after restarting the kernel and running all cells it means you have an error in your code.

Fin#