from numpy.core import double
epsilon = double(input('Введите E > 0: '))
n = 1
sum = 0
def factorial(n):
fact = 1
while n > 1:
fact *= n
n -= 1
return fact
def X3factorial(n):
fact = 1
n = n * 3
while n > 1:
fact *= n
n -= 1
return fact
an = (3 * factorial(n))/X3factorial(n)
while an > epsilon:
n = 1 + n
sum = sum + an
X3factorial(n)
factorial(n)
an = (3 * factorial(n)) / X3factorial(n)
# print(an)
if an < epsilon:
break
print(n)
print(sum)
import wikipedia
def IsLanguageExistInWikipedia(language):
return 'language' in wikipedia.languages()
def LanguageSetup(language):
return IsLanguageExistInWikipedia(language) and wikipedia.set_lang(language)
def CountWordsInPage(page):
return len(page.summary.split())
def MaximumCountWordsOnPagesAndTitle(names):
maximum = -1
title = ""
for name in names:
count = CountWordsInPage(wikipedia.page(name))
if count >= maximum:
maximum = count
title = name
return f"{maximum} {title}"
def IsPageAvailable(name):
try:
wikipedia.page(name)
except Exception:
return False
return True
def CreateChain(names):
chain = [names[0]]
for index in range(len(names) - 1):
page = wikipedia.page(names[index])
if names[index + 1] in page.links:
chain.append(names[index + 1])
else:
for link in page.links:
if not IsPageAvailable(link):
continue
intermediate = wikipedia.page(link)
if names[index + 1] in intermediate.links:
chain.append(intermediate.title)
chain.append(names[index + 1])
break
return(chain)
input = ['Чуумпу далай', 'Хоту Америка', 'Континент', 'sah']
# input = input().split(', ')
if not IsLanguageExistInWikipedia(language):
print('no results')
else:
LanguageSetup(input[-1])
print(MaximumCountWordsOnPagesAndTitle(input[0:-1]))
print(CreateChain(input[0:-1]))