Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Time on Mars is easily divided into days based on its rotation rate and years based on its orbit. Sols, or Martian solar days, are

Time on Mars is easily divided into days based on its rotation rate and years based on its orbit. Sols, or Martian solar days, are only 39 minutes and 35 seconds longer than Earth days, and there are 668 sols (687 Earth days) in a Martian year (2026 through 2028)

 

help me with a program that takes a date as input and outputs the date's season in the northern hemisphere of Mars. The input is an int representing the year, a string to representing the month and an int representing the day.

 

Because seasons in Mars change every ~2 years, the only valid dates we are going to allow here are September 30, 2026 through August 17, 2028.

 

Ex: If the input is:

2027 April 10

the output is:

Spring

In addition, check if the string and int are valid (an actual year, month and day) as follows: 

  • "Invalid year" if the year is not in the range of 2026 through 2028
  • "Invalid month" if the month is not January through December (case matters!)
  • "Invalid day" if the day is not in the 1-30 range. For simplicity, assume every month in Mars has exactly 30 days. 

Ex: If the input is:

2031 Blue 32

the output is:

Invalid year Invalid month Invalid day

Finally, if the year, month and day inputs are valid (with in the range, etc) but they are outside of the dates below (before 9/30/2026 or after 08/17/2028), output 'Invalid input combination'. For example, if the input is: 

2026 July 01

The output is: 

Invalid input combination

The dates for each season in the northern hemisphere of Mars are:

  • Spring: September 30, 2026 - April 16, 2027
  • Summer: April 17, 2027 - October 17, 2027
  • Autumn: October 18, 2027 - March 12, 2028
  • Winter: March 13, 2028 - August 17, 2028

 

Recommended Code Plan

  1. provide a dictionary of month -> month_number (for example 'January' maps to '01'
  2. Clean up the input: make sure the year is in the correct range, make sure the month is in your dictionary, make sure the day is in the correct range (1 - 30, per the simplification)
  3. During #2, print if anything is invalid, and keep track of whether to proceed by having a variable that is set to True if the program should keep going (all the inputs are good so far).
  4. provide a string representing the date selected by the user. Create something like YYYY-MM-DD where YYYY is a four digit year, MM is a two digit month and DD is a two digit day. Example: 2027-01-03.
    • Note that the month and the day have a preceding zero if they have a single digit, make sure that happens before proceeding.
  5. Compare the string generated in #4 with the constants already created for you in the template to determine the season to print. For example, the user input represented in your string in #4 is "09-09-2023', it can be compared with _SPRING_EQUINOX by using:

if generated_string >= _SPRING_EQUINOX and generated_string < _SUMMER_SOLSTICE: [...]

6. If the dates are out of range, print "Invalid input combination"


Step by Step Solution

3.45 Rating (152 Votes )

There are 3 Steps involved in it

Step: 1

Python Define a dictionary to map month names to month numbers monthtonumber January 01 Februar... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

A Concise Introduction to Logic

Authors: Patrick J. Hurley, Lori Watson

13th edition

1305958098, 978-1305958098

More Books

Students also viewed these Programming questions

Question

In Exercises 1558, find each product. (9 - 5x) 2

Answered: 1 week ago