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
  Βad Input on line 12 Azdaghost 4 898 Mar-25-2025, 02:40 PM
Last Post: deanhystad
  How to revert back to a previous line from user input Sharkenn64u 2 788 Dec-28-2024, 08:02 AM
Last Post: Pedroski55
  How to make it so whatever I input into a script gets outputted on a different file spermatozwario 4 1,084 Nov-24-2024, 12:58 PM
Last Post: deanhystad
  Receive Input on Same Line? johnywhy 8 2,490 Jan-16-2024, 03:45 AM
Last Post: johnywhy
  how to make sure an input is from the wanted type astral_travel 16 4,938 Oct-31-2022, 04:11 PM
Last Post: astral_travel
  How to make for loop display on 1 Line Extra 3 2,189 Jan-12-2022, 09:29 PM
Last Post: Extra
  How to input & output parameters from command line argument shantanu97 1 3,536 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 4,568 Apr-04-2021, 06:10 PM
Last Post: Adrian_L
  goto jmabrito 34 15,146 Feb-18-2021, 09:55 PM
Last Post: jmabrito
  Multi-line console input lizze 4 3,503 Dec-26-2020, 08:10 AM
Last Post: lizze

Forum Jump:

User Panel Messages

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