Question

In: Computer Science

USE PYTHON to find out What day of the week is a given date? i.e. On...

USE PYTHON to find out

What day of the week is a given date? i.e. On what day of the week was 5 August 1967? if it is given that 1 January 1900 was a tuesday

Write a function is_leap() which takes 1 input argument, an integer representing a year, and returns True if the year was a leap year, and False if it was not.

.Then, write a function days_since() which takes 3 input integers day, month, year, representing a date (after 1st January 1900), and returns the total number of days passed since the 1st January 1900. (For example, days_since(2, 1, 1900) should return 1. Our day_month = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]

and day_month_leap = [everthing in day_month +1]

Finally, write a function week_day() which takes 3 input integers day, month, year, representing a date (after 1st January 1900), and prints the day of the week corresponding to the date

Dont use any inbuilt function, use looping

Solutions

Expert Solution

Python 3 code :

# check if its a leap year
# If a year is leap, it is divisible by 4 but not by 400
def is_leap(year):
    if (year % 4) == 0:
        if (year % 100) == 0:
            if (year % 400) == 0:
                return True
            else:
                return False
        else:
            return True
    return False

# Checking how many days have passed since 1 January 1990
def days_since(date, month, year):
    n1 = 726833    # days of 1 January 1990 from 00/00/0000 

    # calculating days of given date from 00/00/0000
    n2 = year * 365 + date 
    for i in range(0, month - 1):
        n2 += monthDays[i]
    years = year

    if month <= 2:
        years -= 1
    n2 += int(years / 4 - years / 100 + years / 400)
    # Returning the difference of the 2 dates
    return n2 - n1

# Printing the day of the week
def week_day(date, month, year):
    days = days_since(date, month, year)
    print(days_of_week[days % 7])


monthDays = [31, 28, 31, 30, 31, 30,
             31, 31, 30, 31, 30, 31]
days_of_week = ["Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday"]
months=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November",
        "December"]
date,month,year=map(int,input("Enter the date in format:DD MM YYYY: ").split())
if is_leap(year):
    print("It is a Leap year")
else:
    print("It is not a Leap year")
print("Since 1 January 1990 it has been {} days".format(days_since(date,month,year)))
print("{} {} {} is a ".format(date,months[month-1],year),end="")
week_day(date,month,year)

Screenshot for reference:

Output Screenshot:


Related Solutions

What day of the week is a given date? i.e. On what day of the week...
What day of the week is a given date? i.e. On what day of the week was 5 August 1967? if it is given that 1 January 1900 was a tuesday Write a function is leap() which takes 1 input argument, an integer representing a year, and returns True if the year was a leap year, and False if it was not. .Then, write a function days_since() which takes 3 input integers day, month, year, representing a date (after 1st...
Complete the code so that it can convert the date to day of week using python,...
Complete the code so that it can convert the date to day of week using python, the code should pass the doctest def convert_datetime_to_dayofweek(datetime_string): """ This function takes date in the format MON DAY YEAR HH:MM(PM/AM) and returns the day of the week Assume input string is UTC    >>> convert_datetime_to_dayofweek('Jun 1 2005 1:33PM') 'Wednesday' >>> convert_datetime_to_dayofweek('Oct 25 2012 2:17AM') 'Thursday' """ # code goes here
PYTHON PROGRAM: Write a program that determines the day of the week for any given calendar...
PYTHON PROGRAM: Write a program that determines the day of the week for any given calendar date after January 1, 1900, which was a Monday. This program will need to account for leap years, which occur in every year that is divisible by 4, except for years that are divisible by 100 but are not divisible by 400. For example, 1900 was not a leap year, but 2000 was a leap year.
Determining Maturity Date Find the maturity date of the following: 120-day note dated May 16 90-day...
Determining Maturity Date Find the maturity date of the following: 120-day note dated May 16 90-day note dated November 9 Calculate Maturity Value Find the maturity value of the following: $8,800 6% 9 months $12,000 2% 75 days Journalizing Notes for Buyer and Seller For each of the following transactions for Jackson Co. (the seller), journalize what the entry would be for the buyer (North Co.). Jackson Company uses the periodic method. Accounts Receivable, North Co. 7,800    Sales 7,800 Sold...
Find out how can we use cryptography libraries in Python. Write down the steps to install...
Find out how can we use cryptography libraries in Python. Write down the steps to install cryptography library in Python.
Python 3 In the field where it says failure day indicate current date if i run...
Python 3 In the field where it says failure day indicate current date if i run the program today it show todays date and if i run the program tomorrow it show me tomorrows date and so on . The program is rewriting the product everytime it gets executed i want to add new products as a list in excel # required library import tkinter as tk from tkcalendar import DateEntry import xlsxwriter # frame window = tk.Tk() window.title("daily logs")...
Python 3 In the field where it says failure day indicate current date if i run...
Python 3 In the field where it says failure day indicate current date if i run the program today it show todays date and if i run the program tomorrow it show me tomorrows date and so on . The program is rewriting the product everytime it gets executed i want to add new products as a list in excel # required library import tkinter as tk from tkcalendar import DateEntry import xlsxwriter # frame window = tk.Tk() window.title("daily logs")...
Find out the goals of the agreement, the date established, the countries participating, and summarize principal...
Find out the goals of the agreement, the date established, the countries participating, and summarize principal points of the agreement regarding tariffs, intellectual property, foreign direct investment, and rules regulating environmental, health and safety, minimum wages, and child labor. Research two of the following examples of regional economic cooperation. In 3 paragraphs TPP (Trans Pacific Partnership) APEC (Asia-Pacific Economic Cooperation) Mercosur (Southern Common Market) ASEAN (Association of Southeast Asian Nations)
You have to use the numbers that is given to figure out what the question is...
You have to use the numbers that is given to figure out what the question is asking. 1. You are the Nutrition and Food Services Director and your Chief Financial Officer (CFO) has requested that you evaluate the inventory within the department. Specifically, the CFO wishes to know if the facility is effectively managing the inventory.    To accomplish this task, you will evaluate the inventory turnover from the previous quarter. You have determined the following information: Inventory value at the...
This week, your assignment is to go out into the real world and find a product...
This week, your assignment is to go out into the real world and find a product or service of your choosing, then using the components of the 4E framework listed above, outline how an entrepreneur marketing this product or service can augment or enhance his or her marketing mix efforts via social media.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT