A
A
Asho3232020-06-11 14:22:51
Python
Asho323, 2020-06-11 14:22:51

Write new code or tweak?

Find in the number Pi the number of the digit in the fractional part after which there is a sequence of: six 9, six 8, six 0, the first six digits, seven digits of the phone?
Write new code or fix this one

spoiler
phone = "8977895" # 7-и значный номер телефона 
constants = ["999999", "888888", "000000", "123456", phone] 
 
const_max_len = max([len(constant) for constant in constants]) 
constants_pos = [-1]*len(constants) 
 
size = 65536 #по сколько байт считывать за раз 
 
pos = 0 
old = '' 
with open("C:\Users\Глеб\Desktop") as f: 
 null = f.read(1) 
 while True: 
 data = old + f.read(size) 
 if data == old: break 
 
 for i in range(len(constants)): 
 if constants_pos[i] == -1: 
 j = data.find(constants[i]) 
 if j != -1: constants_pos[i] = j + pos 
 
 pos = pos + len(data) - const_max_len 
 old = data[-const_max_len
 
 for (a, b) in zip(constants, constants_pos): 
 print(f'{a} встречается на позиции {b}')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alan Gibizov, 2020-06-11
@phaggi

Write new

S
Sergei Chamkin, 2020-06-12
@Sergei1337

You can tweak this code a little, but it's easy to google.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question