Skip to content

Instantly share code, notes, and snippets.

@Link-God
Created February 9, 2021 18:28
Show Gist options
  • Save Link-God/98275c2c2bd1d4e24b6576d0dafa30f4 to your computer and use it in GitHub Desktop.
Save Link-God/98275c2c2bd1d4e24b6576d0dafa30f4 to your computer and use it in GitHub Desktop.
ТЧ
from fractions import Fraction
# a, b = map(int, input('Write a/b\n').split('/'))
# alpha = Fraction(a, b)
alpha = 2 ** 0.5
temp = alpha
counter = 0
q_list = []
while counter < 15:
int_temp = int(temp)
# print(int_temp)
q_list.append(int_temp)
try:
temp = (temp - int_temp) ** -1
except ZeroDivisionError:
break
counter += 1
P_list = [1, q_list[0]]
Q_list = [0, 1]
index = 2
for q in q_list[1:]:
cur_P = q * P_list[index - 1] + P_list[index - 2]
cur_Q = q * Q_list[index - 1] + Q_list[index - 2]
P_list.append(cur_P)
Q_list.append(cur_Q)
index += 1
print(q_list, P_list, Q_list, sep='\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment