Предмет: Информатика, автор: arsenkd99

1) Дано натуральне число N. Вивести значення суми
Вираз N! - "N факторіал" - позначає добуток всіх натуральних чисел від 1 до N, тобто N! = 1 • 2 • ... • N.
Отримане число S є наближеним значенням константи e = exp (1) = 2.71828183 ....
Визначити Е - точність знайденого значення експоненти. (E=|S-exp(1)| )


2) Дано дійсне число R (задати в діалозі) і масив розміру N (обрати
самостійно в діапазоні від 7 до 12). Знайти елемент масиву, який
найбільш близький до даного числа (різниця між елементом масива і числом R мінімальна)

Ответы

Автор ответа: p15
1

Ответ:

1. Формулы вычисления не было, потому читал и искал теорию. чем больше n, тем лучше точность. Но не задавайте большие значение n, потому что после примерно 20 (даже раньше) нет смысла (уже точности вычислений не хватает), а например 1000 - будет сообщение об ошибке.

import math

def factorial(n):

   return 1 if n==1 else n*factorial(n-1)

n,s=int(input()),2

for k in range(2,n+1):

   s+=1/factorial(k)

print('вычисленное е=',s,'\nE=',abs(s-math.exp(1)))

2.

import random

R,N=float(input()),10

a=[random.randint(-10,10) for i in range(N)]

print(a)

b=list(map(lambda x:abs(x-R),a))

print(b.index(min(b)))

Объяснение:

постарался как можно более кратко с максимально понятным языком

Интересные вопросы
Предмет: История, автор: gdhtecbjjyj
Предмет: История, автор: kajrovicartem
Предмет: Английский язык, автор: ася051101
Change the following sentences into the Passive Voice. Using the Continuous Tenses. Example: They are solving a difficult problem now. — The problem is being solved now. 1. Don't come in! The professor is examining students. 2. Can I read the article? — No, the secretary is typing it. 3. We had to hurry. They were waiting for us. 4. It was noisy. Nobody was listening to him. 5. Does he realize that they are laughing at him? 6. Look at this man. I think he is following us. 7. Listen carefully! He is giving a very interesting talk. 8. The waiter is serving us rather fast, 9. The secretary was looking through morning mail. 10. The interpreter is translating their conversation rather well. 11. The briefing is in full swing. The correspondents are interviewing the participants of the conference. 12. The company was developing a new project. 13. You can't watch the film now. The mechanic is fixing the TV set. С using the Continuous Tenses. Example: They are solving a difficult problem now. — The problem is being solved now. 1. Don't come in! The professor is examining students. 2. Can I read the article? — No, the secretary is typing it. 3. We had to hurry. They were waiting for us. 4. It was noisy. Nobody was listening to him. 5. Does he realize that they are laughing at him? 6. Look at this man. I think he is following us. 7. Listen carefully! He is giving a very interesting talk. 8. The waiter is serving us rather fast, 9. The secretary was looking through morning mail. 10. The interpreter is translating their conversation rather well. 11. The briefing is in full swing. The correspondents are interviewing the participants of the conference. 12. The company was developing a new project. 13. You can't watch the film now. The mechanic is fixing the TV set.