Q:

Python: Date to Day conversion

Part of my midterm project is to convert a date (month and day) to the number day it is (1-366, including leap year), but I am unsure how to do this. I don't know how to make it work and I also don't know how to make it so you can only put in valid months (ie. Error, make sure to capitalize january.)
Below is what I have done so far.
#Months
January=0
February=31
March=60
April=91
May=121
June=152
July=182
August=213
September=244
October=274
November=305
December=335

#Title
print("Convert: Date to day and day to date.")

#user inputs a date
month=input("\nPick a Month (Make sure to capitalize the first letter): ")

day=int(input("Pick the day of the date you wish to input: "))
if day<0 or day>31:
    print("Error, no months have greater than 31 days or less than 1 day.")

Please help. I have been working on this for the past few days and still cannot figure out how to do it.

A:

I'm not very experienced in Python, so don't expect this to work like a charm and expect some room from improvement to be available. However, I tried this on my computer and it worked out fine. I will try to make this code more efficient and post that later.
I'm not sure if this code will work for your purpose, but I used what you gave me.
You also may want to prompt the user to enter a year in to determine whether the code is looking for dates to a year or leap year, but I'm not sure if you want that so I will leave it out for now. In this code, you can enter in the month however you want.
if you simply want to print the number of days into the year the entered date would be, then you may want to try something like the following (This program exits on incorrect answer as well):
#Months
#January=0
#February=31
#March=60
#April=91
#May=121
#June=152
#July=182
#August=213
#September=244
#October=274
#November=305
#December=335

monthvalue = -1

#Title
print("Convert: Date to day and day to date.")

#user inputs a date
month = input("\nPick a Month (Make sure to capitalize the first letter): ")
month = month.lower()
month = month[:1].capitalize() + month[1:]

if(month=="January"):
    monthvalue = 0

if(month=="February"):
    monthvalue = 31

if(month=="March"):
    monthvalue = 60

if(month=="April"):
    monthvalue = 91

if(month=="May"):
    monthvalue = 121

if(month=="June"):
    monthvalue = 152

if(month=="July"):
    monthvalue = 182

if(month=="August"):
    monthvalue = 213

if(month=="September"):
    monthvalue = 244

if(month=="October"):
    monthvalue = 274

if(month=="November"):
    monthvalue = 305

if(month=="December"):
    monthvalue = 335

if(monthvalue<0):
    print("Error, you have not entered a valid month.")
    xwdwa=input("\nPress any key to continue...")
    exit(0)

day=int(input("Pick the day of the date you wish to input: "))
if day<1 or day>31:
    print("Error, no months have greater than 31 days or less than 1 day.")

total = monthvalue + day

print("Your date is ", total, " days into a leap year.")
exitvar = input("Press any key to continue.")

