Let's try to refactor your original code a bit:
exrate = 100
sales = 0
def sim(var, min, max):
for var in range(min, max):
turnover = 1000 * (exrate/100) + sales
print(turnover)
First, we can factor out the function used in sim, which would be:
def f(exrate, sales):
return 1000 * (exrate/100) + sales
and that function can be simplified further 1000/100=10:
def f(exrate, sales):
return 10 * exrate + sales
You're using globals exrate=100, sales=0 but that's not a good idea, so lets' get rid of those globals by just using default parameters:
def f(exrate=100, sales=0):
return 10 * exrate + sales
Now, at this point we've got a mathy function we can use as input to another functions, it's a function with one single responsability.
So let's say we want to see how this function evolves with respect to one of its independent variables (exrate or sales):
for i in range(100, 1000, 100):
print(f(exrate=i))
for i in range(0, 1000, 200):
print(f(sales=i))
Or both:
for i in range(0, 1000, 200):
print(f(exrate=200, sales=i))
The main idea would be, when simulating something is a good idea to split the code into code that does the simulation (plotting the function in a graph, print values onto a console, ...) and the code which is the simulation itself (in this case, a simple linear function of the form f(x)=ax+b)
turnoverdefined? the variablevarisexrateinside the function. You may first need to clean up variable names.self.exrateandself.salesin the function you define?varargument it's passed because it creates a local variable of the same name. What would you want the function to do with the variable (or variable name) it's passed?