diff --git a/week2/t1.py b/week2/t1.py new file mode 100644 index 0000000..9ceaf38 --- /dev/null +++ b/week2/t1.py @@ -0,0 +1,2 @@ +n = int(input()) +print(n // 60 % 24, ":", n % 60) \ No newline at end of file diff --git a/week2/t2.py b/week2/t2.py new file mode 100644 index 0000000..f6e02f4 --- /dev/null +++ b/week2/t2.py @@ -0,0 +1,3 @@ +text = str(input()) +n = int(input()) +print("Hello" + (", " + text) * n) \ No newline at end of file diff --git a/week2/t3.py b/week2/t3.py new file mode 100644 index 0000000..f885a2a --- /dev/null +++ b/week2/t3.py @@ -0,0 +1,2 @@ +a, b, c = map(int, input().split()) +print(min(min(a, b), c)) \ No newline at end of file diff --git a/week2/t4.py b/week2/t4.py new file mode 100644 index 0000000..040788f --- /dev/null +++ b/week2/t4.py @@ -0,0 +1,5 @@ +v, t = map(int, input().split()) +if v > 0: + print((v * t) % 109) +else: + print(109 - (abs(v) * t) % 109) \ No newline at end of file diff --git a/week2/t5.py b/week2/t5.py new file mode 100644 index 0000000..22f8338 --- /dev/null +++ b/week2/t5.py @@ -0,0 +1,7 @@ +n = int(input()) +s = 0 +f = 1 +for i in range(1, n + 1): + f *= i + s += f +print(s) \ No newline at end of file diff --git a/week2/t6.py b/week2/t6.py new file mode 100644 index 0000000..8cce798 --- /dev/null +++ b/week2/t6.py @@ -0,0 +1,14 @@ +a = [] +c = int(input()) +while c != 0: + a.append(c) + c = int(input()) +max_a = 0 +max2_a = 0 +for i in range(len(a)): + if a[i] > max_a: + max_a = a[i] +for i in range(len(a)): + if a[i] > max2_a and a[i] != max_a: + max2_a = a[i] +print(max2_a) \ No newline at end of file diff --git a/week2/t7.py b/week2/t7.py new file mode 100644 index 0000000..6c8aa98 --- /dev/null +++ b/week2/t7.py @@ -0,0 +1,8 @@ +a = [] +c = int(input()) +while c != 0: + a.append(c) + c = int(input()) +for i in range(len(a)): + if i % 2: + print(a[i]) \ No newline at end of file diff --git a/week2/t8.py b/week2/t8.py new file mode 100644 index 0000000..d9a90bb --- /dev/null +++ b/week2/t8.py @@ -0,0 +1,8 @@ +a = [] +c = int(input()) +while c != 0: + a.append(c) + c = int(input()) +for elem in a: + if elem % 2 == 0: + print(elem) \ No newline at end of file diff --git a/week2/t9.py b/week2/t9.py new file mode 100644 index 0000000..15909c0 --- /dev/null +++ b/week2/t9.py @@ -0,0 +1,7 @@ +import math +def distance(x1, x2, y1, y2): + return(math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)) + + +x1, y1, x2, y2 = map(int, input().split()) +print(r(x1, x2, y1, y2)) \ No newline at end of file diff --git a/week3/w03t2.py b/week3/w03t2.py new file mode 100644 index 0000000..a814054 --- /dev/null +++ b/week3/w03t2.py @@ -0,0 +1,12 @@ +import turtle + +turtle.shape('turtle') +turtle.forward(50) +turtle.left(90) +turtle.forward(50) +turtle.left(90) +turtle.forward(50) +turtle.right(90) +turtle.forward(50) +turtle.right(90) +turtle.forward(50) \ No newline at end of file diff --git a/week3/w3t10.py b/week3/w3t10.py new file mode 100644 index 0000000..24c2d90 --- /dev/null +++ b/week3/w3t10.py @@ -0,0 +1,12 @@ +import turtle + +def circle(): + for i in range(180): + turtle.forward(1) + turtle.left(2) + +turtle.shape('turtle') +for i in range(6): + circle() + turtle.left(60) +#по 2 градуса чтобы быстрее рисовало \ No newline at end of file diff --git a/week3/w3t11.py b/week3/w3t11.py new file mode 100644 index 0000000..de0a628 --- /dev/null +++ b/week3/w3t11.py @@ -0,0 +1,19 @@ +import turtle + +def circle(n, *, direction): + if direction == 'left': + for i in range(180): + turtle.forward(n) + turtle.left(2) + else: + for i in range(180): + turtle.forward(n) + turtle.right(2) + +turtle.shape('turtle') +turtle.left(90) +length = 0 +for i in range(1, 11): + length += 0.5 + circle(length, direction = 'left') + circle(length, direction = 'right') \ No newline at end of file diff --git a/week3/w3t12.py b/week3/w3t12.py new file mode 100644 index 0000000..28d0a94 --- /dev/null +++ b/week3/w3t12.py @@ -0,0 +1,12 @@ +import turtle + +def arc(c): + for i in range(90): + turtle.forward(c) + turtle.right(2) + +turtle.shape('turtle') +turtle.left(90) +for i in range(5): + arc(2) + arc(0.5) \ No newline at end of file diff --git a/week3/w3t13.py b/week3/w3t13.py new file mode 100644 index 0000000..5a17107 --- /dev/null +++ b/week3/w3t13.py @@ -0,0 +1,38 @@ +import turtle + +def arc(c): + for i in range(90): + turtle.forward(c) + turtle.right(2) + +def circle(c): + for i in range(180): + turtle.forward(c) + turtle.left(2) + +turtle.shape('turtle') +turtle.width(5) +turtle.begin_fill() +turtle.color('yellow') +circle(3) +turtle.end_fill() +turtle.left(90) +turtle.color('black') +turtle.penup() +turtle.goto(20,100) +turtle.pendown() +turtle.width(2) +arc(0.7) +turtle.left(180) +turtle.penup() +turtle.goto(-50,100) +turtle.pendown() +arc(0.7) +turtle.penup() +turtle.goto(30,50) +turtle.pendown() +turtle.begin_fill() +arc(1) +turtle.goto(30, 50) +turtle.end_fill() +#надеюсь со смайликом можно было пофантазировать? \ No newline at end of file diff --git a/week3/w3t14_11.py b/week3/w3t14_11.py new file mode 100644 index 0000000..40c146e --- /dev/null +++ b/week3/w3t14_11.py @@ -0,0 +1,6 @@ +import turtle + +turtle.shape('turtle') +for i in range(11): + turtle.forward(100) + turtle.left(163.636363) \ No newline at end of file diff --git a/week3/w3t14_5.py b/week3/w3t14_5.py new file mode 100644 index 0000000..ef82ef2 --- /dev/null +++ b/week3/w3t14_5.py @@ -0,0 +1,6 @@ +import turtle + +turtle.shape('turtle') +for i in range(5): + turtle.forward(100) + turtle.right(144) \ No newline at end of file diff --git a/week3/w3t3.py b/week3/w3t3.py new file mode 100644 index 0000000..bcb7d7b --- /dev/null +++ b/week3/w3t3.py @@ -0,0 +1,6 @@ +import turtle + +turtle.shape('turtle') +for i in range(4): + turtle.forward(40) + turtle.left(90) \ No newline at end of file diff --git a/week3/w3t4.py b/week3/w3t4.py new file mode 100644 index 0000000..141e94e --- /dev/null +++ b/week3/w3t4.py @@ -0,0 +1,6 @@ +import turtle + +turtle.shape('turtle') +for i in range(360): + turtle.forward(2) + turtle.left(1) \ No newline at end of file diff --git a/week3/w3t5.py b/week3/w3t5.py new file mode 100644 index 0000000..26fe24a --- /dev/null +++ b/week3/w3t5.py @@ -0,0 +1,14 @@ +import turtle + +turtle.shape('turtle') +for i in range(1, 11): + turtle.forward(i * 20) + for j in range(3): + turtle.left(90) + turtle.forward(i * 20) + turtle.penup() + turtle.forward(10) + turtle.right(90) + turtle.forward(10) + turtle.pendown() + turtle.left(180) \ No newline at end of file diff --git a/week3/w3t6.py b/week3/w3t6.py new file mode 100644 index 0000000..e083d5f --- /dev/null +++ b/week3/w3t6.py @@ -0,0 +1,10 @@ +import turtle + +n = int(input()) +turtle.shape('turtle') +for i in range(n): + turtle.forward(70) + turtle.stamp() + turtle.left(180) + turtle.forward(70) + turtle.left(180 - 360 // n) \ No newline at end of file diff --git a/week3/w3t7.py b/week3/w3t7.py new file mode 100644 index 0000000..ed131e3 --- /dev/null +++ b/week3/w3t7.py @@ -0,0 +1,6 @@ +import turtle + +turtle.shape('turtle') +for i in range(3600): + turtle.forward(0.1 + i * 0.001) + turtle.left(2) #по 2 градуса чтобы быстрее рисовала \ No newline at end of file diff --git a/week3/w3t8.py b/week3/w3t8.py new file mode 100644 index 0000000..b216395 --- /dev/null +++ b/week3/w3t8.py @@ -0,0 +1,6 @@ +import turtle + +turtle.shape('turtle') +for i in range(4 * 10): + turtle.forward(i * 10) + turtle.left(90) \ No newline at end of file diff --git a/week3/w3t9.py b/week3/w3t9.py new file mode 100644 index 0000000..590f2e3 --- /dev/null +++ b/week3/w3t9.py @@ -0,0 +1,18 @@ +import turtle + +def polygon(n): + l = (15 + n * 5) + turtle.forward(l) + for i in range(n - 1): + turtle.left(360 / n) + turtle.forward(l) + +turtle.shape('turtle') +for i in range(3, 13): + angle = 90 - 180 / i + turtle.left(180 - angle) + polygon(i) + turtle.right(angle) + turtle.penup() + turtle.forward(10) + turtle.pendown() \ No newline at end of file diff --git a/week4/w4t1.py b/week4/w4t1.py new file mode 100644 index 0000000..7f2997a --- /dev/null +++ b/week4/w4t1.py @@ -0,0 +1,9 @@ +arr = [] +amount = 0 +num = int(input()) +for i in range(num): + arr.append(int(input())) +for i in range(1, num - 1): + if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]: + amount += 1 +print(amount) \ No newline at end of file diff --git a/week4/w4t10.py b/week4/w4t10.py new file mode 100644 index 0000000..c00ef6c --- /dev/null +++ b/week4/w4t10.py @@ -0,0 +1,23 @@ +def sort(dictionary): + keys = list(dictionary.keys()) + dictionary_final = {} + keys.sort() + for key in keys: + dictionary_final[key] = dictionary[key] + return dictionary_final + + +n = int(input()) +summary = {} +for i in range(n): + customer, item, amount = input().split() + if summary.get(customer) is None: + summary[customer] = {} + if summary[customer].get(item) is not None: + summary[customer][item] += int(amount) + else: + summary[customer][item] = int(amount) +customers = list(summary.keys()) +for customer in customers: + print(customer) + print(sort(summary[customer])) \ No newline at end of file diff --git a/week4/w4t2.py b/week4/w4t2.py new file mode 100644 index 0000000..24ef107 --- /dev/null +++ b/week4/w4t2.py @@ -0,0 +1,17 @@ +n = int(input()) +a = [] +c = int(input()) +a.append(c) +minimum, maximum = c +max_i, min_i = 0 +for i in range(n - 1): + c = int(input()) + a.append(c) +for i in range(n): + if a[i] > maximum: + max_i = i + maximum = a[i] + elif a[i] < minimum: + min_i = i + minimum = a[i] +a[max_i], a[min_i] = a[min_i], a[max_i] \ No newline at end of file diff --git a/week4/w4t3.py b/week4/w4t3.py new file mode 100644 index 0000000..1e73b7d --- /dev/null +++ b/week4/w4t3.py @@ -0,0 +1,11 @@ +n = int(input()) +a = [] +for i in range(n): + c = int(input()) + a.append(c) +k = 0 +for i in range(n): + for j in range(i + 1, n): + if a[i] == a[j]: + k += 1 +print(k) \ No newline at end of file diff --git a/week4/w4t4.py b/week4/w4t4.py new file mode 100644 index 0000000..249d50a --- /dev/null +++ b/week4/w4t4.py @@ -0,0 +1,11 @@ +n = int(input()) +a = {} +for i in range(n): + key = str(input()) + if key in a: + a[key] += 1 + else: + a[key] = 1 +for key in a: + if a[key] == 1: + print(key) \ No newline at end of file diff --git a/week4/w4t5.py b/week4/w4t5.py new file mode 100644 index 0000000..896a959 --- /dev/null +++ b/week4/w4t5.py @@ -0,0 +1,13 @@ +def sort(a): + for i in range(len(a)): + for j in range(i, len(a)): + if a[i] > a[j]: + c = a[i] + a[i] = a[j] + a[j] = c + return(a) + + +a = set(input().split()) +b = set(input().split()) +print(sort(list(a.intersection(b)))) \ No newline at end of file diff --git a/week4/w4t6.py b/week4/w4t6.py new file mode 100644 index 0000000..5188fa0 --- /dev/null +++ b/week4/w4t6.py @@ -0,0 +1,8 @@ +s = list(map(int, input().split())) +s1 = set() +for elem in s: + if elem in s1: + print('YES') + else: + print('NO') + s1.add(elem) \ No newline at end of file diff --git a/week4/w4t7.py b/week4/w4t7.py new file mode 100644 index 0000000..f85a11f --- /dev/null +++ b/week4/w4t7.py @@ -0,0 +1,7 @@ +n = int(input()) +text = set() +for i in range(n): + s = input().split() + for elem in s: + text.add(elem) +print(len(text)) \ No newline at end of file diff --git a/week4/w4t8.py b/week4/w4t8.py new file mode 100644 index 0000000..b2c250d --- /dev/null +++ b/week4/w4t8.py @@ -0,0 +1,8 @@ +n = int(input()) +dict_syn = {} +for i in range(n): + word, synonym = input().split() + dict_syn[word] = synonym + dict_syn[synonym] = word +word_orig = str(input()) +print(dict_syn[word_orig]) \ No newline at end of file diff --git a/week4/w4t9.py b/week4/w4t9.py new file mode 100644 index 0000000..661c112 --- /dev/null +++ b/week4/w4t9.py @@ -0,0 +1,24 @@ +n = int(input()) +amount = {} +text = [] +maximum = 0 +word_max = '' +for i in range(n): + s = input().split() + text += s +for i in range(len(text)): + if amount.get(text[i]) is None: + amount[text[i]] = 1 + else: + amount[text[i]] += 1 + if amount[text[i]] > maximum: + maximum = amount[text[i]] + word_max = text[i] + elif amount[text[i]] == maximum and text[i] < word_max: + maximum = amount[text[i]] + word_max = text[i] +print(amount) #бонусное задание посчитать сколько раз встречается каждое слово +for i in range(len(text)): + if text[i] == word_max: + print(text[i]) + break \ No newline at end of file diff --git a/week5/w5t1.py b/week5/w5t1.py new file mode 100644 index 0000000..5c7bca0 --- /dev/null +++ b/week5/w5t1.py @@ -0,0 +1,12 @@ +def power(a, n): + a1 = 1 + if n > 0: + for i in range(n): + a1 *= a + elif n < 0: + for i in range(abs(n)): + a1 /= a + return(a1) + +a, n = map(int, input().split()) +print(power(a, n)) \ No newline at end of file diff --git a/week5/w5t2.py b/week5/w5t2.py new file mode 100644 index 0000000..2b36bcb --- /dev/null +++ b/week5/w5t2.py @@ -0,0 +1,25 @@ +def gcd(a,b): + if b == 0: + return(a) + else: + return(gcd(b, a % b)) + +print("Enter the amount of pairs of numbers") +n = int(input()) +print("Choose the way you want to receive answer:") +print("1. After every pair I've entered") +print("2. After all pairs I've entered") +print("Enter the number of the way you've chosen") +way = int(input()) +if way == 1: + for i in range(n): + a, b = map(int,input().split()) + print(gcd(a,b)) +elif way == 2: + pairs_gcd = [] + for i in range(n): + a, b = map(int, input().split()) + pairs_gcd.append(gcd(a,b)) + print(pairs_gcd) +else: + print("Wrong input, please try again") \ No newline at end of file diff --git a/week5/w5t3.py b/week5/w5t3.py new file mode 100644 index 0000000..525998e --- /dev/null +++ b/week5/w5t3.py @@ -0,0 +1,62 @@ +import math + +def circle(r): + return math.pi * r * r + +def triangle(*, height = None, side1 = None, side2 = None, side3 = None, angle = None): + if height == None: + if angle == None: + p = 0.5 * (side1 + side2 + side3) + return math.sqrt(p * (p - side1) * (p - side2) * (p - side3)) + else: + return side1 * side2 * 0.5 * math.sin(angle * math.pi / 180) + else: + return 0.5 * side1 * height +def rectangle(*, side1 = None, side2 = None, d1 = None, d2 = None, angle = None): + if angle == None: + return side1 * side2 + else: + return d1 * d2 * 0.5 * math.sin(angle * math.pi / 180) +print("Enter the shape type:") +shape = str(input()) +if shape == 'circle' or shape == 'Circle': + print('Enter the radius') + r = int(input()) + print(circle(r)) +elif shape == 'triangle' or shape == 'Triangle': + print("Choose the way you want to calculate the area:") + print("1. Side and its height") + print("2. Two sides and angle between them") + print("3. Three sides") + print("Enter the number of the way you've chosen") + way = int(input()) + if way == 1: + print( "Enter side and its height") + side, height = map(int, input().split()) + print(triangle(side1 = side, height = height)) + elif way == 2: + print("Enter two sides and angle between them") + side1, side2, angle = map(int, input().split()) + print(triangle(side1 = side1, side2 = side2, angle = angle)) + elif way == 3: + print("Enter three sides") + side1, side2, side3 = map(int, input().split()) + print(triangle(side1 =side1, side2 = side2, side3 = side3)) + else: + print("Wrong input, please try again") +elif shape == 'rectangle' or shape == 'Rectangle': + print("Choose the way you want to calculate the area:") + print("1. Two sides") + print("2. Two diagonals and angle between them") + print("Enter the number of the way you've chosen") + way = int(input()) + if way == 1: + print("Enter two sides") + side1, side2 = map(int, input().split()) + print(rectangle(side1 = side1, side2 = side2)) + elif way == 2: + print("Enter two diagonals and angle between them") + d1, d2, angle = map(int, input().split()) + print(rectangle(d1 = d1, d2 = d2, angle = angle)) +else: + print('Wrong type, please try again') \ No newline at end of file diff --git a/week5/w5t4.py b/week5/w5t4.py new file mode 100644 index 0000000..4d1bad5 --- /dev/null +++ b/week5/w5t4.py @@ -0,0 +1,19 @@ +print("Enter the amount of strings in your matrix") +n = int(input()) +print("Enter your matrix line by line") +matrix = [] +for i in range(n): + matrix.append(input().split()) +print("Enter the type of the diagonal you want to calculate") +diagonal = input() +summ = 0 +if diagonal == 'main' or diagonal == "Main": + for i in range(n): + summ += int(matrix[i][i]) + print(summ) +elif diagonal == 'side' or diagonal == "Side": + for i in range(n): + summ += int(matrix[i][n - i]) + print(summ) +else: + print("Wrong input, please try again") \ No newline at end of file diff --git a/week5/w5t5.py b/week5/w5t5.py new file mode 100644 index 0000000..ea21ab0 --- /dev/null +++ b/week5/w5t5.py @@ -0,0 +1,20 @@ +import matplotlib.pyplot as plt + +def f (x): + if x < -5: + return(2 * abs(x) - 1) + elif x > 5: + return(2 * x) + else: + return(x ** 2) + +x, y = [], [] +for i in range(21): + x.append(i - 10) +for elem in x: + y.append(f(elem)) +plt.plot(x, y) +plt.xlabel("x") +plt.ylabel("y") +plt.grid(True, alpha = 0.5) +plt.show() \ No newline at end of file