This program converts a date given from the French Republican Calendar to the corresponding date in our standard Gregorian Calendar. I'm looking for some improvements that I should start making in my code as well as some tips on how to write less lengthy code.
For example, the RepubtoGregDate function is very long and I believe there is probably a more effective way of implementing it.
I'm very new to Python and have no prior knowledge in programming so it would nice to have some suggestions in how to improve my code.
#Python Assignment - French Republican to Gregorian Date Convertor
#Coded by - -
import sys
def Main():
Startup()
while True:
dayN, monthN, yearN, date = Date()
StopProgram(date)
ValidDate = DateVal(yearN, monthN, dayN)
ValLoop(ValidDate)
monthW = MonthNtoW(monthN)
yearRN = YearNtoRN(yearN)
RepubDate = FullRepubDate(dayN, monthW, yearRN)
Leap = LeapCheck(yearN)
GrDate = RepubtoGregDate(yearN, monthN, dayN, Leap)
def Startup():
print("Republican to Gregorian Date Converter\n")
print("This program will convert a date from the French Republican Calendar to the equivalent date in the Gregorian Calendar.")
print("To stop calculating dates and close the program, simply input: 0 0 0.\n")
# Asks for a Republican Date and returns day, month and year.
def Date():
print("Input a Republican Date in the format: dd mm yy.")
date = input("Please enter a Republican Date: ")
print("")
date = date.split()
dayN = int(date[0])
monthN = int(date[1])
yearN = int(date[2])
return(dayN, monthN, yearN, date)
# Ends the program if the sentinal is matched.
def StopProgram(date):
if date == ['0', '0', '0']:
sys.exit(print("Program Closed."))
# Validates the date, making sure it fits the Republican format and that
# the date is between the calendars real world use: 1793 - 1806.
def DateVal(yearN, monthN, dayN):
if yearN >= 1 and yearN <= 14:
ValidYear = True
else:
ValidYear = False
if monthN >= 1 and monthN <= 12:
ValidMonth = True
else:
ValidMonth = False
if dayN >= 1 and dayN <= 30:
ValidDay = True
else:
ValidDay = False
if yearN < 2 and monthN < 1 and dayN < 14:
InvalidDate = True
elif yearN > 14 and monthN > 4 and dayN > 11:
InvalidDate = True
else:
InvalidDate = False
if ValidYear == True and ValidMonth == True and ValidDay == True and InvalidDate == False:
ValidDate = True
else:
ValidDate = False
return(ValidDate)
# Repeats the Date() Function if the Date is invalid.
def ValLoop(ValidDate):
while ValidDate == False:
print("The entered date was not a valid gregorian date, please try again.")
dayN, monthN, yearN = Date()
# Finds the month number's corresponding month word.
def MonthNtoW(monthN):
MonthWDict = {1 : "Vendémiaire", 2 : "Brumaire", 3 : "Frimaire", 4 : "Nivôse", 5 : "Pluviôse", 6 : "Ventôse", 7 : "Germinal", 8 : "Floréal", 9 : "Prairial", 10 : "Messidor", 11 : "Thermidor", 12 : "Fructidor"}
monthW = MonthWDict[monthN]
return monthW
# Finds the year number's corresponding year in roman numerals.
def YearNtoRN(yearN):
YearRNDict = {1 : "I", 2 : "II", 3 : "III", 4 : "IV", 5 : "V", 6 : "VI", 7 : "VII", 8 : "VIII", 9 : "IX", 10 : "X", 11 : "XI", 12 : "XII", 13 : "XIII", 14 : "XIV"}
yearRN = YearRNDict[yearN]
return(yearRN)
# Outputs the Republican date in its written format.
def FullRepubDate(dayN, monthW, yearRN):
dayN = str(dayN)
RepubDate = dayN + " " + monthW + " an " + yearRN
print("The French Republican Date is: ", RepubDate)
dayN = int(dayN)
return(RepubDate)
# Checks if the year is a leap year.
def LeapCheck(yearN):
if yearN == 3 or yearN == 7 or yearN == 11:
Leap = True
else:
Leap = False
return(Leap)
# Converts the Republican date to a Gregorian date.
# It does this by converting the date to days in the year and then adds
# that to the day the Republican Calendar started in The Gregorian calendar.
def RepubtoGregDate(yearN, monthN, dayN, Leap):
monthL = 30
StartDate = 266
StartYear = 1792
YDays = 365
LYDays = 366
Year = StartYear + (yearN - 1)
Day = ((monthN - 1) * monthL) + dayN
if Leap == True and Day >= 60:
Day += 1
PH = StartDate + Day
if Leap == True:
if PH > LYDays:
Year += 1
Day = PH - LYDays
else:
Day = PH
if Leap == False:
if PH > YDays:
Year += 1
Day = PH - YDays
else:
Day = PH
if Leap == False:
if Day >= 1 and Day <= 31:
GregMonth = "January"
if Day >= 32 and Day <= 59:
Day -= 31
GregMonth = "February"
if Day >= 60 and Day <= 90:
Day -= 59
GregMonth = "March"
if Day >= 91 and Day <= 120:
Day -= 90
GregMonth = "April"
if Day >= 121 and Day <= 151:
Day -= 120
GregMonth = "May"
if Day >= 152 and Day <= 181:
Day -= 151
GregMonth = "June"
if Day >= 182 and Day <= 212:
Day -= 181
GregMonth = "July"
if Day >= 213 and Day <= 243:
Day -= 212
GregMonth = "August"
if Day >= 244 and Day <= 273:
Day -= 243
GregMonth = "September"
if Day >= 274 and Day <= 304:
Day -= 273
GregMonth = "October"
if Day >= 305 and Day <= 334:
Day -= 304
GregMonth = "November"
if Day >= 335 and Day <= 365:
Day -= 334
GregMonth = "December"
if Leap == True:
if Day >= 1 and Day <= 31:
GregMonth = "January"
if Day >= 32 and Day <= 60:
Day -= 32
GregMonth = "February"
if Day >= 61 and Day <= 91:
Day -= 60
GregMonth = "March"
if Day >= 92 and Day <= 121:
Day -= 91
GregMonth = "April"
if Day >= 122 and Day <= 152:
Day -= 121
GregMonth = "May"
if Day >= 153 and Day <= 182:
Day -= 152
GregMonth = "June"
if Day >= 183 and Day <= 213:
Day -= 182
GregMonth = "July"
if Day >= 214 and Day <= 244:
Day -= 213
GregMonth = "August"
if Day >= 245 and Day <= 274:
Day -= 244
GregMonth = "September"
if Day >= 275 and Day <= 305:
Day -= 274
GregMonth = "October"
if Day >= 306 and Day <= 335:
Day -= 305
GregMonth = "November"
if Day >= 336 and Day <= 366:
Day -= 335
GregMonth = "December"
Day = str(Day)
Year = str (Year)
GregDate = Day + " " + GregMonth + " " + Year
Day = int(Day)
Year = int(Year)
print("The Gregorian Date is: ", GregDate, "\n")
return(GregDate)
#Main
Main()
dayN, monthN, yearN = Date()
ValueError: too many values to unpack (expected 3)
When I try to run, it will give me an error. Also unclear to me what Dates are valid... \$\endgroup\$