Python Forum

Full Version: How to make input goto a different line
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm relatively new to Python and coding and general although I've been doing batch and HTML for a while. My friend wants me to make a sales tax calculator for the state of Ohio, and since almost every county has a different rate, I have multiple lines I need the computer to read to get the correct total of a sale. For example, if he needs to find the total sale of something in Franklin county, he'll input "Franklin" and now the code needs to jump to Franklin to calculate the tax and sale. I though it would be an "if" statement or a "goto" statement but I'm not finding anything. Thank you in advance.
Is this homework?
you can use a dictionary which contains 'countyname': function_name entries,
example:
command = {
    'franklin': func1,
    'ashland': func2,
    'butler': func3,
    'logan': func4
}
can show full example if not homework
Although Larz+ is right and this is a good place to use a dictionary I'm very surprised at your "not finding anything" comment as this is a classic use case for the "if" statement:

tax = None
county = "Franklin" 

if county == "Springfield":
    tax = 0.075
elif county == "Franklin":
    tax = 0.05
elif county == "Riverside":
    tax = 0.032
else:
    tax = 0.40

print(tax)