Hey, I have the following issue:

#definition tax rates (defined for all states)

rate_Texas = 0.11

rate_California = 0.13

rate_Florida = 0.09

rate_Federal = 0.21

#selection state (example)

state = Texas

#calculation tax rate

tax_rate = rate_Federal + rate_**state**

I want to use a formula, for which the rate_state is automatically replaced by the rate of the selected state (Texas in this case). The goal is to have just one formula for the calculation of the tax rate and not one for all states.

How can I do this?

Thank you very much and regards

Edit to clarify: You can’t manipulate variable names like that. You will need to replicate the logic without the variable name manipulation, and a dictionary let’s you do that.

Original post:

I think the most Pythonic way to do this would be to make a dictionary.

```
state_rates = {
"Texas" : 0.11,
"California" : 0.13,
...
}
```

You can then access the values by the state.

Thank you. However, then I would still need a tax rate calculation formula for each state, which is not handy in my case (the tax rate calculation is much more extensive than the formula in my example)

You don’t need to have a different calculation for each state if you use a dictionary.

What happens when you try this code:

```
state_rates = {
"Texas" : 0.11,
"California" : 0.13,
}
my_state = "Texas"
print(state_rates[my_state])
```

If you mean that the calculation is more complex than a single number, a dictionary is still the right way to go. You can make a dictionary out of anything, even functions!

By the way, I started talking about dictionaries because you can’t manipulate variable names like you want. A dictionary gives you the logic you are describing with manipulating the variable name itself, which is not possible.