10 월 15 일 이후로 요일을 알아 내려면 산술의 간단한 부분을 사용할 수있다. 내 문제는 내가 파일에서 날짜를 읽었다는 것이다. (예 : 2009-06 -12) 그리고 난에 방정식을 뒀다 :파이썬 3.3에서 방정식을 풀다.
w = (d + [2.6 * m - 0.2] + Y + [Y/4] + 5 * C + [C/4]) % 7
날짜는 yyyy-mm-dd 형식에 내 코드는 다음과 같습니다
count = 5
f = open('/Users/student/Desktop/Harry.txt').readlines()[count]
Y = f[2:4]
C = f[:2]
m = f[5:7]
d = f[8:10]
w = (d + [2.6 * m - 0.2] + Y + [Y/4] + 5 * C + [C/4]) % 7
if w == 0:
print (f, "is a Sunday")
elif w == 1:
print (f, "is a Monday")
elif w == 2:
print (f, "is a Tuesday")
elif w == 3:
print (f, "is a Wednesday")
elif w == 4:
print (f, "is a Thursday")
elif w == 5:
print (f, "is a Friday")
elif w == 6:
print (f, "is a Saturday")
가 명확히 :
w = day of the week counting from Sunday = 0 Monday = 1
d = the day of the month (for e.g. 28th 13th)
m = month number where March = 1 etc.
Y = last 2 digits of year
C = first 2 digits of year
01 23,516,
아직 내가
Traceback (most recent call last):
File "/Users/student/Documents/workspace/Tutorial Challenges/src/Day_Of_The_Week.py", line 7, in <module>
w = (d + [2.6 * m - 0.2] + Y + [Y/4] + 5 * C + [C/4]) % 7
TypeError: can't multiply sequence by non-int of type 'float'
도움을 주시면 감사하겠습니다이 오류가 발생합니다.
필자 내가 'INT'추가 – Obcure
추가 정보 '목록'을 변경 기운으로 아직이하자 나던 것을 tryed. – user2357112
예 tryed도 여전히 작동하지 않는 ?? – Obcure