Question

In: Computer Science

Python 3.7.4: The current calendar, called the Gregorian calendar, was introduced in 1582. Every year divisible...

Python 3.7.4:

The current calendar, called the Gregorian calendar, was introduced in 1582. Every year divisible by four was created to be a leap year, with the exception of the years ending in 00 (that is, those divisible by 100) and not divisible by 400. For ­instance, the years 1600 and 2000 are leap years, but 1700, 1800, and 1900 are not. Write a program that requests a year as input and states whether it is a leap year. We need to run this as many times as the user wants to check for leap years.

Below was marked incorrect for me. I need to put it in a while loop. Also, I'm curious if there is a way to do it without def? Do we have to call main? Sorry for all of the newbie questions. Thank you!

----------------------

def leap(year):
    if(year % 400 == 0):
        return True
    elif year % 100 == 0:
        return False
    elif year%4 == 0:
        return True
    else:
        return False
def main():
    year = int(input("Enter year: "))
    if(leap(year)):
        print(year,"is a leap year")
    else:
        print(year, "is not a leap year")
main()

Solutions

Expert Solution

Program code in python:

import sys #helps to use sys.exit to exit from the program

def leap(year): #function to check for leap year
if(year % 400 == 0):
return True
elif year % 100 == 0:
return False
elif year%4 == 0:
return True
else:
return False
def main(): #function to enter year
year = int(input("Enter year: "))
if(leap(year)):
print(year,"is a leap year")
else:
print(year, "is not a leap year")
replayMain()
  
def replayMain(): #function to get the choice to continue
ch = int(input("Do you want to continue: Press 1 to continue and 0 to exit.... "))
if(ch == 1):
main()
else:
sys.exit
main() #main function call

Screenshots attached below:

Screenshot of the python code:

Screenshot of sample output:

Please "Like" if this helped!  Good luck!

Editted as per request to use something instead of sys.exit.....

You can also use break instead of sys.exit.

The code will be as :

def leap(year): #function to check for leap year
if(year % 400 == 0):
return True
elif year % 100 == 0:
return False
elif year%4 == 0:
return True
else:
return False
def main(): #function to enter year
year = int(input("Enter year: "))
if(leap(year)):
print(year,"is a leap year")
else:
print(year, "is not a leap year")
replayMain()
  
def replayMain(): #function to get the choice to continue
ch = int(input("Do you want to continue: Press 1 to continue and 0 to exit.... "))
while ch == 0:
break #exits the program
else:
main()
main() #main function call

code screenshot:

output:

Good luck!


Related Solutions

In Java Please!!! 5.24 LAB: Leap year A year in the modern Gregorian Calendar consists of...
In Java Please!!! 5.24 LAB: 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)...
Cranberry Corporation has $3,240,000 of current year taxable income. If the current year is a calendar...
Cranberry Corporation has $3,240,000 of current year taxable income. If the current year is a calendar year ending on December 31, 2017, calculate Cranberry's regular income tax liability. If the current year is a calendar year ending on December 31, 2018, calculate Cranberry’s regular income tax liability. If the current year is a fiscal year ending on April 30, 2018, calculate Cranberry's regular income tax liability. (Do not round intermediate calculations.)
Python 3 Fix this: show the current date where the calendar field is # required library...
Python 3 Fix this: show the current date where the calendar field is # required library import tkinter as tk from tkcalendar import DateEntry import xlsxwriter # frame window = tk.Tk() window.title("daily logs") #window.resizable(0,0) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=3, sticky="W", pady=20, padx=20) # entries barcode = tk.Entry(window) product = tk.Entry(window) money = tk.Entry(window) # arraging barcode.grid(row=0, column=1) product.grid(row=1, column=1) money.grid(row=2, column=1) cal...
Python 3 Fix the code so everytime i hit clear the calendar resets to the current...
Python 3 Fix the code so everytime i hit clear the calendar resets to the current date in case it was modified Code: import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook from tkinter import messagebox window = tk.Tk() window.title("daily logs") window.grid_columnconfigure(1,weight=1) window.grid_rowconfigure(1,weight=1) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="sold by").grid(row=3, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=4, sticky="W", pady=20, padx=20) # entries...
Python 3 Fix the code so everytime i hit clear the calendar resets to the current...
Python 3 Fix the code so everytime i hit clear the calendar resets to the current date in case it was modified Code: import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook from tkinter import messagebox window = tk.Tk() window.title("daily logs") window.grid_columnconfigure(1,weight=1) window.grid_rowconfigure(1,weight=1) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="sold by").grid(row=3, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=4, sticky="W", pady=20, padx=20) # entries...
Python 3 Fix the code so everytime i hit clear the calendar resets to the current...
Python 3 Fix the code so everytime i hit clear the calendar resets to the current date in case it was modified Code: import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook from tkinter import messagebox window = tk.Tk() window.title("daily logs") window.grid_columnconfigure(1,weight=1) window.grid_rowconfigure(1,weight=1) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="sold by").grid(row=3, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=4, sticky="W", pady=20, padx=20) # entries...
3. At the beginning of the year, Poplock began a calendar-year dog boarding business called Griff’s...
3. At the beginning of the year, Poplock began a calendar-year dog boarding business called Griff’s Palace. Poplock bought and placed in service the following assets during the year: Asset                                 Date Acquired   Cost Basis Computer equipment      3/23                       $5,000 Dog grooming furniture  5/12                          $7,000 Pickup truck                      9/17                     $10,000 Commercial building       10/11                    $280,000 Land (one acre)                10/11                    $80,000 Assuming Poplock does not elect §179 expensing or bonus depreciation, what is Poplock’s year 1 depreciation expense for each asset?
Revenue and expense data for the current calendar year for Dawg Electronics Company and for the...
Revenue and expense data for the current calendar year for Dawg Electronics Company and for the electronics industry are as follows. Dawg Electronics Company data are expressed in dollars. The electronics industry averages are expressed in percentages. Dawg Electronics Company Electronics Industry Average Sales $ 3,750,000 100 % Cost of goods sold (2,062,500) (61.0) Gross profit $1,687,500 39.0 % Selling expenses $(1,125,000) (23.0) % Administrative expenses (262,500) (10.0) Total operating expenses $(1,387,500) (33.0) % Operating income $300,000 6.0 % Other...
Revenue and expense data for the current calendar year for Tannenhill Company and for the electronics...
Revenue and expense data for the current calendar year for Tannenhill Company and for the electronics industry are as follows. Tannenhill’s data are expressed in dollars. The electronics industry averages are expressed in percentages. 1 Tannenhill Company Electronics Industry Average 2 Sales $4,920,000.00 100.0% 3 Cost of goods sold 2,533,800.00 56.5 4 Gross profit $2,386,200.00 43.5% 5 Selling expenses $1,328,400.00 24.0% 6 Administrative expenses 787,200.00 14.0 7 Total operating expenses $2,115,600.00 38.0% 8 Operating income $270,600.00 5.5% 9 Other revenue...
On December 10 of the current year, Gonzalez Corporation (a calendar-year taxpayer) accrues an obligation for...
On December 10 of the current year, Gonzalez Corporation (a calendar-year taxpayer) accrues an obligation for a $125,000 bonus to Latasha, a sales representative who had had an outstanding year. Latasha owns no Gonzalez Corporation stock. The bonus is paid on May 5 of the next year. What is Gonzalez's deduction for the current year? What is Gonzalez's deduction for next year? Explain you answer.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT