Find Jobs
Hire Freelancers

Python Leap year program

$10-30 USD

Completato
Pubblicato più di 8 anni fa

$10-30 USD

Pagato al completamento
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 [login to view URL] 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
Rif. progetto: 8815321

Info sul progetto

3 proposte
Progetto a distanza
Attivo 8 anni fa

Hai voglia di guadagnare un po'?

I vantaggi delle offerte su Freelancer

Imposta il tuo budget e le scadenze
Fatti pagare per il lavoro svolto
Delinea la tua proposta
La registrazione e le offerte sui lavori sono gratuite
Assegnato a:
Avatar dell'utente
Computer science student in his final year. Plenty of experience solving algorithmic problems via code. Python is one of my main languages
$20 USD in 1 giorno
4,9 (4 valutazioni)
2,0
2,0
3 freelance hanno fatto un'offerta media di $25 USD
Avatar dell'utente
A proposal has not yet been provided
$25 USD in 1 giorno
5,0 (5 valutazioni)
4,1
4,1
Avatar dell'utente
A proposal has not yet been provided
$30 USD in 0 giorno
5,0 (4 valutazioni)
2,1
2,1

Info sul cliente

Bandiera: UNITED STATES
campton, United States
4,9
9
Metodo di pagamento verificato
Membro dal gen 12, 2012

Verifica del cliente

Grazie! Ti abbiamo inviato tramite email il link per richiedere il tuo bonus gratuito.
Non è stato possibile inviarti l'email. Riprova per piacere.
di utenti registrati di lavori pubblicati
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Caricamento anteprima
Autorizzazione per la geolocalizzazione concessa.
La tua sessione è scaduta ed è stato effettuato il log out. Accedi nuovamente per piacere.