Python Leap year program

Completado Publicado Nov 1, 2015 Pagado a la entrega
Completado Pagado a la entrega

February 29 is a date that usually occurs every four years, and is called leap day. This day is added to the calendar in leap years as a corrective measure, because the Earth does not orbit around the sun in precisely 365 days.

Write a function called leap1 that will accept one integer as a parameter which represents a year, and will return True if the year is a leap year and False otherwise.

A year is a leap year if it is evenly divisible by 4, unless it is divisible by 100, in which case it must also be divisible by 400. That is, 1996 is a leap year because it is divisible by 4 and not 100, 1997 is not a leap year because it is not divisible by 4, 2000 is a leap year because it is divisible by 100 and 400, and 2100 will not be a leap year because it is divisible by 100 but not 400.

Another take on these same rules:

if the number is divisible by 4 and not divisible by 100, yes it is a leap year

if the number is divisible by 4 and divisible by 100 and divisible by 400, yes it is a leap year

if neither of those hold, then no it is not a leap year

1582 is the earliest year to which these rules apply (see Gregorian calendar for more information) so a year before that should say no

Write this function with only ONE return statement. You will need another variable to hold results through the function body, then return it at the end.

This function does NO input from keyboard nor output to the screen. It has one parameter coming IN and a return value going OUT.

Hint: the mod operator is very useful here.

If you need help with testing this, go to this web page for a leap year calculator.

Write a main function to act as a driver for the leapyear function. It should ask the user repeatedly for a year and call the function properly using the year as the argument. It should output "yes, it is a leap year" if the user's input was a leap year, "no, it is not a leap year" if it was not. It should repeat this action until the user enters a -1. Note that the -1 is NOT used as an argument with the function. Hint: Sentinel logic and a while loop!

Sample run

Enter a year: 2000

Yes, it is a leapyear

Enter a year: 2100

No, it is not a leapyear

Enter a year: 1996

Yes, it is a leapyear

Enter a year: 1600

Yes, it is a leapyear

Enter a year: -1

Once you have that written and tested, write another function called leap2 which does the same thing exactly using ONE statement. It has one parameter and returns a boolean value. The function has a body which is a return statement. Boil down the if statements you used in the first version into one expression which uses the Boolean operators (and, or) to get the result in one step. Test this one too, with the same values as the first version.

use if statements

write a boolean function

write sentinel logic

here is a calculator you can use for help with testing if needed [url removed, login to view]

use # to write comments above code to explain what its doing, like in steps

Must be in a .py file

written in a python IDE such as IDLE or WING

needs to be done tonight by midnight if possible

preferably around $15

Python Arquitectura de software Verificación de software

Nº del proyecto: #8815321

Sobre el proyecto

3 propuestas Proyecto remoto Activo Nov 1, 2015

Adjudicado a:

josemontenegro13

Computer science student in his final year. Plenty of experience solving algorithmic problems via code. Python is one of my main languages

$20 USD en 1 día
(4 comentarios)
2.0

3 freelancers están ofertando un promedio de $25 por este trabajo

privatecaptain

A proposal has not yet been provided

$25 USD en 1 día
(5 comentarios)
4.1
tgogniashvili

A proposal has not yet been provided

$30 USD en 0 días
(4 comentarios)
2.1