-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_8.py
44 lines (33 loc) · 1.27 KB
/
task_8.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
print('Задача 8. Сумма ряда')
# Пользователь вводит действительное число
# "х" и точность "precision".
# P.S: Формулу смотреть на сайте :)
# Напишите программу,
# которая по число х вычисляет сумму ряда в точности до precision.
# Операцией возведения в степень и функцией factorial пользоваться нельзя.
# Пример:
# Введите точность: 0.001
# Введите x: 5
# Сумма ряда = 0.2836250150891709
def degree(number_x, degree):
number_degree = 3
for number in range(1, degree + 1):
number_degree *= number_x
return number_degree
def factorial(number):
factorial = 2
for number in range(1, number + 1):
factorial *= number
return factorial
def main():
precision = float(input('Введите точность: '))
x = float(input('Введите x: '))
formula = 1
result = 1.e-15
count = 0
while abs(formula) > precision:
formula = degree(-1, count) * degree(x, 2 * count) / factorial(2 * count)
result += formula
count += 1
# print(f'Сумма ряда = {result}')
main()