Skip to content

Commit b1995ed

Browse files
Add files via upload
1 parent c801f3c commit b1995ed

File tree

9 files changed

+194
-0
lines changed

9 files changed

+194
-0
lines changed

08 - Data and Time/Calendar Module.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import calendar
2+
3+
month, day, year = map(int, input().split())
4+
5+
print(calendar.day_name[calendar.weekday(year, month, day)].upper())

08 - Data and Time/Time Delta.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/python3
2+
3+
import os
4+
from datetime import datetime
5+
6+
7+
# Complete the time_delta function below.
8+
def time_delta(t1, t2):
9+
time1 = datetime.strptime(t1, '%a %d %b %Y %H:%M:%S %z')
10+
time2 = datetime.strptime(t2, '%a %d %b %Y %H:%M:%S %z')
11+
12+
return str(int(abs((time1 - time2).total_seconds())))
13+
14+
15+
if __name__ == '__main__':
16+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
17+
18+
t = int(input())
19+
for t_itr in range(t):
20+
t1 = input()
21+
t2 = input()
22+
delta = time_delta(t1, t2)
23+
fptr.write(delta + '\n')
24+
25+
fptr.close()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
for i in range(int(input())):
2+
try:
3+
a, b = map(int, input().split())
4+
print(a // b)
5+
except ZeroDivisionError as z:
6+
print(f"Error Code: {z}")
7+
except ValueError as v:
8+
print(f"Error Code: {v}")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import re
2+
3+
for i in range(int(input())):
4+
try:
5+
a = re.compile(input())
6+
print("True")
7+
except Exception:
8+
print("False")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import math
2+
3+
4+
class Points(object):
5+
def __init__(self, x, y, z):
6+
self.x = x
7+
self.y = y
8+
self.z = z
9+
10+
def __sub__(self, no):
11+
return Points((self.x - no.x), (self.y - no.y), (self.z - no.z))
12+
13+
def dot(self, no):
14+
return (self.x * no.x) + (self.y * no.y) + (self.z * no.z)
15+
16+
def cross(self, no):
17+
return Points((self.y * no.z - self.z * no.y), (self.z * no.x - self.x * no.z), (self.x * no.y - self.y * no.x))
18+
19+
def absolute(self):
20+
return pow((self.x ** 2 + self.y ** 2 + self.z ** 2), 0.5)
21+
22+
23+
if __name__ == '__main__':
24+
POINTS = list()
25+
for i in range(4):
26+
A = list(map(float, input().split()))
27+
POINTS.append(A)
28+
29+
A, B, C, D = Points(*POINTS[0]), Points(*POINTS[1]), Points(*POINTS[2]), Points(*POINTS[3])
30+
X = (B - A).cross(C - B)
31+
Y = (C - B).cross(D - C)
32+
ANGLE = math.acos(X.dot(Y) / (X.absolute() * Y.absolute()))
33+
34+
print("%.2f" % math.degrees(ANGLE))
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import math
2+
3+
4+
class Complex(object):
5+
def __init__(self, real, imaginary):
6+
self.real = real
7+
self.imaginary = imaginary
8+
9+
def __add__(self, no):
10+
return Complex((self.real + no.real), self.imaginary + no.imaginary)
11+
12+
def __sub__(self, no):
13+
return Complex((self.real - no.real), self.imaginary - no.imaginary)
14+
15+
def __mul__(self, no):
16+
r = (self.real * no.real) - (self.imaginary * no.imaginary)
17+
i = (self.real * no.imaginary + no.real * self.imaginary)
18+
return Complex(r, i)
19+
20+
def __truediv__(self, no):
21+
conjugate = Complex(no.real, (-no.imaginary))
22+
numerator = self * conjugate
23+
denominator = no * conjugate
24+
try:
25+
return Complex((numerator.real / denominator.real), (numerator.imaginary / denominator.real))
26+
except Exception as e:
27+
print(e)
28+
29+
def mod(self):
30+
m = math.sqrt(self.real ** 2 + self.imaginary ** 2)
31+
return Complex(m, 0)
32+
33+
def __str__(self):
34+
if self.imaginary == 0:
35+
result = "%.2f+0.00i" % self.real
36+
elif self.real == 0:
37+
if self.imaginary >= 0:
38+
result = "0.00+%.2fi" % self.imaginary
39+
else:
40+
result = "0.00-%.2fi" % (abs(self.imaginary))
41+
elif self.imaginary > 0:
42+
result = "%.2f+%.2fi" % (self.real, self.imaginary)
43+
else:
44+
result = "%.2f-%.2fi" % (self.real, abs(self.imaginary))
45+
return result
46+
47+
48+
if __name__ == '__main__':
49+
c = map(float, input().split())
50+
d = map(float, input().split())
51+
x = Complex(*c)
52+
y = Complex(*d)
53+
print(*map(str, [x + y, x - y, x * y, x / y, x.mod(), y.mod()]), sep='\n')
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cube = lambda x: x**3 # complete the lambda function
2+
3+
def fibonacci(n):
4+
# return a list of fibonacci numbers
5+
storage = [0,1]
6+
for i in range(2,n):
7+
storage.append(storage[i -1] + storage[i - 2])
8+
return storage[0:n]
9+
10+
if __name__ == '__main__':
11+
n = int(input())
12+
print(list(map(cube, fibonacci(n))))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from fractions import Fraction
2+
from functools import reduce
3+
4+
5+
def product(fracs):
6+
t = Fraction(reduce(lambda x, y: x * y, fracs)) # complete this line with a reduce statement
7+
return t.numerator, t.denominator
8+
9+
10+
if __name__ == '__main__':
11+
fracs = []
12+
for _ in range(int(input())):
13+
fracs.append(Fraction(*map(int, input().split())))
14+
result = product(fracs)
15+
print(*result)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
def fun(s):
2+
# return True if s is a valid email, else return False
3+
try:
4+
username, url = s.split("@")
5+
website, extension = url.split(".")
6+
except ValueError:
7+
return False
8+
9+
if username.replace("-", "").replace("_", "").isalnum() is False:
10+
return False
11+
12+
elif website.isalnum() is False:
13+
return False
14+
15+
elif len(extension) > 3:
16+
return False
17+
18+
else:
19+
return True
20+
21+
22+
def filter_mail(emails):
23+
return list(filter(fun, emails))
24+
25+
26+
if __name__ == '__main__':
27+
n = int(input())
28+
emails = []
29+
for _ in range(n):
30+
emails.append(input())
31+
32+
filtered_emails = filter_mail(emails)
33+
filtered_emails.sort()
34+
print(filtered_emails)

0 commit comments

Comments
 (0)