Created
February 9, 2021 18:28
-
-
Save Link-God/98275c2c2bd1d4e24b6576d0dafa30f4 to your computer and use it in GitHub Desktop.
ТЧ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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