Python Forum
How to make input goto a different line - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to make input goto a different line (/thread-24197.html)



How to make input goto a different line - mxl671 - Feb-03-2020

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.


RE: How to make input goto a different line - Larz60+ - Feb-03-2020

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


RE: How to make input goto a different line - Marbelous - Feb-04-2020

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)