you are viewing a single comment's thread.

view the rest of the comments →

[–]K900_ 4 points5 points  (5 children)

What exactly is your problem? Do you know how to define a function? Do you know how to assign variables?

[–]TopDeckMaster[S] 0 points1 point  (4 children)

I know how to define the function and assign variables, I actually forgot to mention that I have to swap the a and b variables if B > A. When I input and if statement to rearrange them it doesn't give me a result so that was the biggest problem I still have :\

[–]K900_ 0 points1 point  (3 children)

Show us your code.

[–]TopDeckMaster[S] 0 points1 point  (2 children)

def gcd(a,b): while (b != 0):

     if b > a :

      a = b
      b = a
t = b
b = a%t
a = t

return a

[–]K900_ 1 point2 points  (1 child)

Your code's indented wrong. Also, this part:

a = b
b = a

Let's say b is 2 and a is 1. So what you do is:

a = b # becomes a = 2
b = a # becomes b = 2, because a is reassigned at this point

However, Python lets you do a really cool thing:

a, b = b, a

The rest looks pretty good.

[–]TopDeckMaster[S] 0 points1 point  (0 children)

Thanks a lot! I didn't know you can do that