Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS USES THE LATEST VERSION OF PYTHON: Decisions, decisions, decisions. Computers are terrible at them, so as programmers we need to instruct them on how

THIS USES THE LATEST VERSION OF PYTHON:

Decisions, decisions, decisions. Computers are terrible at them, so as programmers we need to instruct them on how to make good ones. In this lab using python, you will write a program that accepts a date in the form month/day/year and prints whether or not the date is valid. For example 5/24/1962 is valid, but 9/31/2000 is not. (September has only 30 days.)

Your program, in order to be correct, should be able to pass these simple (but far from complete!) test cases:

  • 2/29/2000 (valid)
  • 2/29/2001 (not valid)
  • 4/30/1984 (valid)
  • 4/31/1984 (not valid)
  • 0/12/1234 (not valid)
  • 13/30/2014 (not valid)
  • 10/24/2014 (valid)

Im OK with you allowing leading zeros for the month, or day. This is optional, however.

  • 03/04/2017 (valid)
  • 07/22/2019 (valid)
  • 00/12/1234 (not valid)

Generally speaking, I want to see the following structure in your program. This encourages separation of concerns:

  1. Obviously, you will be using if-elif-else statements to make

    decisions in your program.

  2. The function main() should print a friendly message and ask for the input of the date in the required format (see above). It then should parse the date into its day, month and year components. It will pass this information to a date check function.
  3. A date check function needs to be defined that will take these date components of day, month and year and checks to see if that date is valid.
    • This function is required to return a Python True or False boolean value (reflecting a valid, or invalid date, respectively) that your main() function will use to print out the correct message about the dates validity.
  4. A function that calculates leap year needs to be used by your date check function. This formula should be easy to look up.
    • You need to write this function that takes takes a year as a parameter that will then return a Python True or False boolean value (reflecting a leap, or non-leap year, respectively).

Output

Sample output looks like:

This program accepts a date in the form month/day/year and outputs whether or not the date is valid Please enter a date (mm/dd/yyyy): 2/29/2000 2/29/2000 is valid 

or

This program accepts a date in the form month/day/year and outputs whether or not the date is valid Please enter a date (mm/dd/yyyy): 4/31/1984 4/31/1984 is not valid

SO YOU KNOW:

I AM USING THE LATEST VERSION OF PYTHON. So please make sure I can understand with all the latest rules that python uses! Thanks a bunch!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Nested Relations And Complex Objects In Databases Lncs 361

Authors: Serge Abiteboul ,Patrick C. Fischer ,Hans-Jorg Schek

1st Edition

3540511717, 978-3540511717

More Books

Students also viewed these Databases questions

Question

6. Explain the strengths of a dialectical approach.

Answered: 1 week ago

Question

2. Discuss the types of messages that are communicated nonverbally.

Answered: 1 week ago