Top.Mail.Ru
Ответы

Не работает код, питон

По дате
По рейтингу
Аватар пользователя
Просветленный

Вот эти вот двойные кавычки
Можно либо до цикла объявить либо в случае else:

123456789101112131415161718192021222324252627282930313233343536
 positions = []  # Create a list to store the positions 
 
for N in range(1000, 10000): 
    n = list(map(int, str(N))) 
    g1 = int(n[0]) + int(n[1]) 
    g2 = int(n[1]) + int(n[2]) 
    g3 = int(n[2]) + int(n[3]) 
 
    if g1 < g2 and g1 < g3 and g2 < g3: 
        del(g1) 
        w = int(str(g2) + str(g3)) 
    elif g1 < g2 and g1 < g3 and g3 < g2: 
        del(g1) 
        w = int(str(g3) + str(g2)) 
    elif g2 < g1 and g2 < g3 and g1 < g3: 
        del(g2) 
        w = int(str(g1) + str(g3)) 
    elif g2 < g1 and g2 < g3 and g3 < g1: 
        del(g2) 
        w = int(str(g3) + str(g1)) 
    elif g3 < g1 and g3 < g2 and g2 < g1: 
        del(g3) 
        w = int(str(g2) + str(g1)) 
    elif g3 < g1 and g3 < g2 and g1 < g2: 
        del(g3) 
        w = int(str(g1) + str(g2)) 
    else: 
        print("ha") 
        w = 0 
 
    if w == 1315: 
        positions.append(N)  # Add the position to the list 
 
# Print the positions after the loop 
print(f"Позиции числа 1315: {positions}")