(Jan-10-2022, 04:09 PM)Gribouillis Wrote: It prints only 1 because when youprint("D", f)
the value of the variablef
is the last value that was assigned tof
by a statementf = ...
, and this last value turns out to be 1. Previous values of f are no longer available at that moment.
My misunderstanding comes from the fact that if it was C#, thanks to the curly bracket both loops would be independant and print outside would return indenpendant numbers. I could use the if statement and C# would return 14 , 8, 7, 6, 5, 4, 3 ,2 , 1 .
But it does not seem to be the case with python. I tried a different approach and the same problem is coming back.
a = 154 b = 42 d = 0 f = 0 for (i,j) in zip(range(1,a),range(1,b)): d = round(a / i) print("d", d) f = round(b / j) print("f", f) if (f==d): print("GCD",f)What am i suppose to do? Create a list of d and f and than filter the list to find GCD. Of course there are other way to get GCD but i always find solution with 30 lines. Is it me or Python consume a lot of lines?