Reputation: 90
Problem statement:
According to Gregorian Calendar, it was Monday on the date 01/01/2001. If any year is input, Write a program to display what is the day on the 1st January of this year.
Input
The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer year.
Output
Display the day on the 1st January of that year in lowercase letter.
Constraints
1 ≤ T ≤ 1000
1900≤ A,B,C ≤2500
Example
Input
3
1994
1991
2014
Output
saturday
tuesday
wednesday
Solution I submitted:
import datetime
test = input("Enter no. of test cases ")
while (test):
year = input("Enter the year ")
day = datetime.date(int(year),1,1).strftime("%A")
print (day.lower())
test = int(test)-1
When I run locally everything works fine. The output is the same as given in the test cases. Why is it giving a wrong answer on Codechef?
Upvotes: 1
Views: 338
Reputation: 3580
You don't need to prompt for input, in fact it will give you wrong answer on almost all online judges. Following code gives correct answer.
import datetime
test = int(input())
while test:
year = input()
day = datetime.date(int(year),1,1).strftime("%A")
print(day.lower())
test -= 1
Upvotes: 2