Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calendar program
#1
This is my assignment
calendar program that allows the user to enter a day, month, and year in three separate variables as shown below.

Please enter a date
Day:
Month:
Year:
Then, ask the user to select from a menu of choices using this formatting:

Menu:
1) Calculate the number of days in the given month.
2) Calculate the number of days left in the given year.

this is what i have come up with but it doesn't work properly i've tried everything i can think off or have learned.
def number_of_days(m):
    if (m == 1,3,5,7,8,9,11):
        woh = 31
    elif (m == 2):
        woh = 28
    elif (m == 4,6,10,12):
        woh = 30
    print (woh)

def days_left(d,m,y):
    if (d > 0):
        print ('135')
def leap_year(d,m,y):
    if (d > 0):
        print ('1')
    
day = int(input('Enter the day:'))
month = int(input('Enter the month:'))
year = int(input('Enter the year:'))
menu = int(input('1) Calculate the number of days in a given month or 2) Calculate the number of Day left in year? (1,2)'))
if (menu == 1):
    monthdays = number_of_days(month)
    print (monthdays)
elif (menu == 2):
    dayleft = days_left(day,month,year)
    print (dayleft)
when i run this it asks all the right questions but doesn't calculate properly?
Any help would be appreciated

Thank You this is my first time posting here i will read the document
Reply
#2
First I'd like the point out that days_left doesn't return anything. Next, I don't understand why the function just prints "135". Other than that, to calculate how many days are left, you need to use the number_of_days function. So, make a for loop that iterates from range(m+1, 13), if the month is not 12, and adds up the amount of days into a variable. Then add the amount of days left in the current month to the variable. Also, for the number_of_days function, you'll need to check whether or not the year is a leap year, and if so, then if m=2, return 29 rather than 28. I explained it, so now you just need to put it all together into some code.
Reply
#3
Wow that's a lot thank you. I will start working on it now
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Task calendar problem humanical 8 1,842 Sep-04-2023, 02:55 PM
Last Post: Pedroski55
Sad [Learning] Calendar without modules or list KoFu 5 4,904 Sep-09-2019, 03:25 PM
Last Post: DeaD_EyE
  Calendar calculations frequency 10 5,732 Nov-13-2018, 07:34 PM
Last Post: frequency
  Calendar calcualtions deusvult 11 8,429 May-01-2017, 02:56 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020