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...
Use Zeller’s algorithm to figure out the days of the week for a given date in...
Use Zeller’s algorithm to figure out the days of the week for a given date in c. W = (d + 13(m+1)/5 + y + y/4 + c/4 - 2c + 6) mod 7 Y is the year minus 1 for January or February, and the year for any other month y is the last 2 digits of Y c is the first 2 digits of Y d is the day of the month (1 to 31) m is the...
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.
Write a query to return the date and day of the week of the first day...
Write a query to return the date and day of the week of the first day of the month two years from today. If today is 10/16/20, then the expect output is 10/01/2022 and the day of the week is thursday. I am using postgresql.
FOR PYTHON: Write a python program for a car salesperson who works a five day week....
FOR PYTHON: Write a python program for a car salesperson who works a five day week. The program should prompt for how many cars were sold on each day and then prompt for the selling price of each car (if any) on that day. After the data for all five days have been entered, the program should report the total number of cars sold and the total sales for the period. See example output. NOTE: duplicate the currency format shown...
Day of week Write a program that asks the user for a date (year, then month,...
Day of week Write a program that asks the user for a date (year, then month, then day, each entered as a number on a separate line), then calculates the day of the week that date falls on (according to the Gregorian calendar) and displays the day name. You may not use any date functions built into Python or its standard library, or any other functions that do this work for you. Hint: Reverend Zeller may be useful, but his...
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")...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT