#Function to find the day of the week def dayofweek(data): d = int(data[1]) m =
ID: 3740816 • Letter: #
Question
#Function to find the day of the week
def dayofweek(data):
d = int(data[1])
m = int(data[0])
y = int(data[2])
if m < 3:
z = y-1
else:
z = y
dayofweek = ( 23*m//9 + d + 4 + y + z//4 - z//100 + z//400 )
if m >= 3:
dayofweek -= 2
dayofweek = dayofweek%7
return dayofweek
# creating X1 and Y1 arrays and temp1 dictionary to store day and voilations
X1 = []
Y1 = []
temp = defaultdict(int)
for i in range(len(t1)):
temp[dayofweek(t1[i].split('/'))+1] = temp[dayofweek(t1[i].split('/'))+1]+int(t2[i])
for i in temp:
X1.append(i)
Y1.append(temp[i])
X1 = np.array(X1)
Y1= np.array(Y1)
Z = np.polyfit(X,Y,7)
p = np.poly1d(Z)
import matplotlib.pyplot as plt
xp = np.linspace(-2, 8, 100)
plt.plot(X1, Y1, '.', xp, p(xp), '-')
plt.show()
temp[dayofweek(t1[i].split('/'))+1] = temp[dayofweek(t1[i].split('/'))+1]+int(t2[i]) is the reason why I keep getting an AttributeError and I don't know how to fix this.
Explanation / Answer
# Program to find day
# of a given date d =Day ,m=Month , y =Year
def dayofweek(d, m, y):
t = [ 0, 3, 2, 5, 0, 3,
5, 1, 4, 6, 2, 4 ]
y -= m < 3
return (( y + int(y / 4) - int(y / 100)
+ int(y / 400) + t[m - 1] + d) % 7)
# Driver Code
week=['Sunday','Monday','Tuesday','Wednesday','Thrusday','Friday','Saturday']
day = dayofweek(1, 4, 2018)
print(week[day])
OutPut:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.