[Python] I am not able to store the output in variable

Discussão em 'Python' iniciado por Stack, Setembro 13, 2025.

  1. Stack

    Stack Membro Participativo

    import math

    def gcd(a):
    for i in range (1,a+1):
    b=math.gcd(i,a)
    b+=0
    print(b)

    a=int(input("Enter: "))
    gcd(a)


    This is my code to find GCD of a given number ie.

    1] if a=2 then gcd of (1,2)+ gcd(2,2) = 1+2=3
    2] if a=3 then gcd(1,3)+(2,3)+(3,3) = 1+1+3=5

    but I am unable to store value in b i.e" b+=0 " it doesn't store. I want to get sum of all b as answer

    How to do that?

    (I am beginner in coding).

    Continue reading...

Compartilhe esta Página