[Python] there is some issue when my pc is running this python program, its giving me non-zero...

Discussão em 'Python' iniciado por Stack, Junho 11, 2025.

  1. Stack

    Stack Membro Participativo

    import math
    import sys

    limit = 30

    def f(x):
    if (x - 1)/3 % 1 == 0:
    return int((x-1)/3)
    else:
    return 0

    o1 = []
    o2 = []
    o3 = []
    o4 = []
    a=1

    'o1: '
    while a>0 :
    if a<(limit+1):
    o1.append( (a, f(4**a)) )
    a = a+1
    else:
    a = 0
    break

    'o2: '
    for i in o1:
    o2.append( (i[0], f(i[1])) )

    po2 = []
    while a < len(o2):
    if o2[a][1] == 0:
    a += 1
    continue
    po2.append(o2[a])
    a +=1
    a=0

    'o3: '
    for i in po2:
    o3.append( (i[0], f(i[1])) )

    po3 = []
    while a < len(o3):
    if o3[a][1] == 0:
    a += 1
    continue
    po3.append(o3[a])
    a +=1
    a=0

    'o4: '
    for i in po3:
    o4.append( (i[0], f(i[1])) )

    po4 = []
    while a < len(o4):
    if o4[a][1] == 0:
    a += 1
    continue
    po4.append(o4[a])
    a +=1
    a=0

    'print'
    print(o1)
    print()
    print(o2)
    print(po2)
    print()
    print(o3)
    print(po3)
    print()
    print(o4)
    print(po4)
    print(type(o2[29][1]))
    print(f(4**30))
    print(sys.maxsize) #for me it was 9223372036854775807


    For this python code if u manually check the value for o2[28][1] (aka f(f(4**29))) and o2[29][1] (aka f(f(4**30))) they are non integers and thus should be zero in the list, but wen running the code its giving non zero values on the list, I checked sys.maxsize but its still larger than 4**29 and 4**30. Why is it happening like this and can some one show how to fix it?

    Continue reading...

Compartilhe esta Página