Only thress changes. First you assign for each iteration the name
You have to initialize this outside of the loop to prevent this. Instead of using a loop, put this code in a function.
This function asks only one time. To repeat this, call this function somewhere else in a while-True loop.
Print your results, after you've collected them, otherwise you'll get as first result, then the first two and etc...
This did work with only one result, because the dict was replaced by a new empty dict for each iteration.
But the code has been changed into a function, so the results should be returned and not printed.
Just having one function, which does only one thing, it's easier for later reuse in code and is also easier to change.
list_numbers
to an empty dict.You have to initialize this outside of the loop to prevent this. Instead of using a loop, put this code in a function.
This function asks only one time. To repeat this, call this function somewhere else in a while-True loop.
def ratio(): list_numbers={} a = int(input(' Enter 1st number for ratio calculation: ')) b = int(input(' Enter 2nd number for ratio calculation: ')) y = int(input(' Enter y start range: ')) n = int(input(' Enter n end range: ')) for x in range(y,n): list_numbers.update({a*x: b*x}) return list_numbersThe third change is the print function.
Print your results, after you've collected them, otherwise you'll get as first result, then the first two and etc...
This did work with only one result, because the dict was replaced by a new empty dict for each iteration.
But the code has been changed into a function, so the results should be returned and not printed.
Just having one function, which does only one thing, it's easier for later reuse in code and is also easier to change.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!