Python Forum
How to make input goto a different line
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make input goto a different line
#1
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.
Reply
#2
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
Reply
#3
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)
"So, brave knights, if you do doubt your courage or your strength, come no further, for death awaits you all with nasty, big, pointy teeth!" - Tim the Enchanter
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Receive Input on Same Line? johnywhy 8 717 Jan-16-2024, 03:45 AM
Last Post: johnywhy
  how to make sure an input is from the wanted type astral_travel 16 2,476 Oct-31-2022, 04:11 PM
Last Post: astral_travel
  How to make for loop display on 1 Line Extra 3 1,428 Jan-12-2022, 09:29 PM
Last Post: Extra
  How to input & output parameters from command line argument shantanu97 1 2,565 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  How to make input come after input if certain line inserted and if not runs OtherCode Adrian_L 6 3,338 Apr-04-2021, 06:10 PM
Last Post: Adrian_L
  goto jmabrito 34 10,197 Feb-18-2021, 09:55 PM
Last Post: jmabrito
  Multi-line console input lizze 4 2,366 Dec-26-2020, 08:10 AM
Last Post: lizze
  Make the answer of input int and str enderfran2006 2 2,007 Oct-12-2020, 09:44 AM
Last Post: DeaD_EyE
  bad input line 3 how t fix it youssef210 2 2,701 Aug-27-2020, 04:57 PM
Last Post: nilamo
  Line charts error "'isnan' not supported for the input types," issac_n 1 2,402 Jul-22-2020, 04:34 PM
Last Post: issac_n

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020