+ 1
Need help
In this code final output have to have same value of x and y. So the code should repeat the some conditions. If x > y, then the value of x will be x - y. And so for the y. If y > x, then the value of y will be y - x. Can anybody solve this error with my code? Thank you. https://code.sololearn.com/ctMjEZlcmvAB/?ref=app
3 odpowiedzi
+ 1
Klaudius Liasta 'return' if for functions, not for loops
So:
1) delete the 'return' lines
2) correct the indents in 'if... else' sections
The code will be like this:
x = 2437
y = 875
while True:
if x>y:
x = x - y
elif y>x:
y = y - x
else:
break
print(x,y)
0
Thank you very much. Can I use for loops in that case?
0
Also you can get rid off 'while True' and make the code simpler:
x = 2437
y = 875
while x != y:
if x > y:
x = x - y
else:
y = y - x
print(x,y)