Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Chapter 7, exercise 13: The days of the year are often numbered from 1 through 365 (or 366). This number can be computed in 3

Chapter 7, exercise 13:

The days of the year are often numbered from 1 through 365 (or 366). This number can be computed in 3 steps using int arithmetic:

dayNum = 31(month day) + day

if the month is February subtract (4(month) + 23)//10

if its a leap year and after February 29, add 1

Write a program that accepts a date as month/day/year, verifies that it is a valid date and then calculates the corresponding day number.

My Code:

def leapYear(num):

if num % 400 == 0:

return 1

elif num % 100 == 0:

return 0

else:

return 0

month31 = [1,3,5,7,8,10,12]

month30 = [4,6,9,11]

if month

print(" Please correct date input.")

if month > 12:

print(" Please correct date input.")

if month == 2:

lyear = leapYear(year)

if lyear == 1:

if day = 1:

print("This is a valid date.")

flag=0

else:

print("This is not a valid date.")

flag=1

if lyear == 0:

if day = 1:

print("This is a valid date.")

flag=0

else:

print("This is not a valid date.")

flag=1

for i in month30:

if i == month:

if day >= 1 and day

print("This is a valid date.")

flag=0

else:

print("This is not a valid date.")

flag=1

for i in month31:

if i == month:

if day >= 1 and day

print("This is a valid date.")

flag=0

return flag

def main():

print("This program will check to see if the date is valid.")

date = input("Please enter a date in the form of Month/Day/Year:")

try:

month,day,year = date.split("/")

month = int(month)

day = int(day)

year = int(year)

if lyear == 1:

print("This is a leap year.")

else:

print("This is a normal year.")

result = check(month,day,year)

if result == 0:

num =(31*(month-1)) + day

if month >= 3:

num = num-((4*month)+23)//10

if month >= 3 and lyear == 1:

num = num + 1

print("The number is:", num)

except ValueError:

print(" Please correct the date input")

main()

Code Screenshots:

image text in transcribedimage text in transcribedimage text in transcribed

I keep getting the same error regardless if it is a normal year or a leap year. Please help, thank you.

image text in transcribedimage text in transcribed

def leapYear (num): if num % 400--0: return 1 elif num % 100-0: return 0 else: return 0 month31 -[1,3,5,7,8,10,12] month30 = [ 4, 6, 9, 11] if month = 1: print ("This is a valid date.") flag 0 else: print ("This is not a valid date.") flag-l if 1year-0: if day = 1: print ("This is a valid date.") flag 0 else: print ("This is not a valid date.") flag-l for i in month30

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions