if message.text == 'Подтвердить':
всегда вернется одно и то же значение.cells_products_data
.const fib = (n, a = []) => {
if (n < 1) {
a[0] = 0n;
a[1] = 1n;
} else {
const m = Math.floor(n/2);
fib(m, a);
const x = a[0] * (2n * a[1] - a[0]);
const y = a[0] * a[0] + a[1] * a[1];
if (n % 2) {
a[0] = y;
a[1] = x + y;
} else {
a[0] = x;
a[1] = y;
}
}
return a;
}
const sumFib3n = (n) => {
if (n < 1) { return 0n; }
const [fn, fnp1] = fib(n); // fn = fib(n), fnp1 = fib(n+1),
const fnm1 = fnp1 - fn; // fnm1 = fib(n-1),
const sgn = n % 2 ? 1n : -1n;
const sumPow3 = (fn * fnp1 * fnp1 + sgn * fnm1 + 1n) / 2n;
return sumPow3 - 1n + fn * fn * fn + fnp1 * fnp1 * fnp1;
}
console.log(sumFib3n(Math.floor((40000000 - 2)/3)));
from functools import lru_cache
@lru_cache
def F(n):
print(n)
if n <= 1:
return n
if n>1:
return F(n-1)+F(n-2)
F(8)
Вот твоя функция в точности, я добавил кеширование результатов, и print(n). Запусти с ним и без него и посмотри сколько лишних вызовов происходит. Если владеешь английским вот хорошая статья почитай как сделать своими руками, без встроенного декоратора, различные стратегии и т.д. https://realpython.com/lru-cache-python/ import tkinter as tk
from tkinter import ttk
import asyncio
class App:
async def exec(self):
self.window = Window(asyncio.get_event_loop())
await self.window.show();
class Window(tk.Tk):
def __init__(self, loop):
self.loop = loop
self.root = tk.Tk()
self.animation = "░▒▒▒▒▒"
self.label = tk.Label(text="")
self.label.grid(row=0, columnspan=2, padx=(8, 8), pady=(16, 0))
self.progressbar = ttk.Progressbar(length=280)
self.progressbar.grid(row=1, columnspan=2, padx=(8, 8), pady=(16, 0))
button_block = tk.Button(text="Calculate Sync", width=10, command=self.calculate_sync)
button_block.grid(row=2, column=0, sticky=tk.W, padx=8, pady=8)
button_non_block = tk.Button(text="Calculate Async", width=10, command=lambda: self.loop.create_task(self.calculate_async()))
button_non_block.grid(row=2, column=1, sticky=tk.W, padx=8, pady=8)
async def show(self):
while True:
self.label["text"] = self.animation
self.animation = self.animation[1:] + self.animation[0]
self.root.update()
await asyncio.sleep(.1)
def calculate_sync(self):
max = 3000000
for i in range(1, max):
self.progressbar["value"] = i / max * 100
async def calculate_async(self):
max = 3000000
for i in range(1, max):
self.progressbar["value"] = i / max * 100
if i % 1000 == 0:
await asyncio.sleep(0)
asyncio.run(App().exec())
("хорошо" or "прекрасно" or "отлично" or "пойдет")
>>> # Import the Decimal type from the decimal module
>>> from decimal import Decimal
>>> # Values are represented exactly so no rounding error occurs
>>> Decimal("0.1") + Decimal("0.2") == Decimal("0.3")
True
>>> # By default 28 significant figures are preserved
>>> Decimal(1) / Decimal(7)
Decimal('0.1428571428571428571428571429')
>>> # You can change the significant figures if needed
>>> from decimal import getcontext
>>> getcontext().prec = 6 # Use 6 significant figures
>>> Decimal(1) / Decimal(7)
Decimal('0.142857')
myfile = open('test.txt', 'w')
encrypted_password_file = open('password_database.txt', 'r') # viewing the password database
password_database
with open('password_database.txt', 'rt') as encrypted_password_file:
# код