+ 1

This code is supposed to print the day corresponding to a date..... The main() function is not being executed.....why?

date=input("Enter the date in 'dd/mm/yyyy' format") day=int(date[0:2]) month=int(date[3:5]) year=int(date[6:11]) def calculate(): a=int(year/4) b=int(year/100) c=int(year/400) if (year%4==0 and year%100!=0) or (year%4==0 and year%400==0): yearcount=(year-1)*365+a-b+c-1 else: yearcount=(year-1)*365+a-b+c ar=[31,28,31,30,31,30,31,31,30,31,30,31] i=0 monthcount=0 while(i<month): monthcount+=i total=yearcount+monthcount+day return total def giveDay(total): if total<7: if total==0: print(date,"/",month,"/",year," is Sunday!") elif total==1: print(date,"/",month,"/",year," is Monday!") elif total==2: print(date,"/",month,"/",year," is Tuesday!") elif total==3: print(date,"/",month,"/",year," is Wednesday!") elif total==4: print(date,"/",month,"/",year," is Thursday!") elif total==5: print(date,"/",month,"/",year," is Friday!") elif total==6: print(date,"/",month,"/",year," is Saturday!") else: if total%7==0: print(date,"/",month,"/",year," is Sunday!") elif total%7==1: print

19th Oct 2019, 9:18 PM
Mohammed Mesum Hussain
Mohammed Mesum Hussain - avatar
3 odpowiedzi
+ 1
In python functions have to be made before you call them, so the order of the functions should be calculate(): giveDay(total): And the "main" (assuming you mean the first code block) Then in the main you call calculate() and giveDay(total) You should have the calculate function take in a parameter for the year variable as well.
19th Oct 2019, 10:49 PM
Odyel
Odyel - avatar
+ 1
Jan Markus this is exactly what you are telling.....an exercise I know such programs already exists
20th Oct 2019, 7:26 AM
Mohammed Mesum Hussain
Mohammed Mesum Hussain - avatar
0
Kilowac the code that I posted has been cut down, I did exactly what you told Then I implemented If __name__=="__main__": main () In main() I called calculate() and giveDay() Still not working
20th Oct 2019, 7:24 AM
Mohammed Mesum Hussain
Mohammed Mesum Hussain - avatar