Bottom Page

Thread Rating:
  • 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to write switch case statement in Python
Quote:Frankly, both examples are overcomplicated
Yes, a simple list will do. This omits the input portion of the code as that is not part of the "case statement".
day_of_week=["Sunday". "Monday", "Tuesday", "Wednesday",
                     "Thursday", "Friday", "Saturday"]
if input_day in day_of_week:
    return day_of_week.index(input_day)
    print("\nInvalid Entry, Please try again")

Top Page

Messages In This Thread
RE: How to write switch case statement in Python - by woooee - Nov-11-2018, 08:53 PM

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to use switch/case in python? newbieguy 9 303 Nov-08-2019, 11:35 AM
Last Post: newbieguy
  How to switch table area coordinates in Python Camelot and Tabula-Py john5 0 701 May-08-2019, 04:31 PM
Last Post: john5
  Is there a better way to write this case scenario? anakaine 15 3,236 Sep-26-2017, 04:33 PM
Last Post: buran
  Is there a something like "case" in Python 3.6? Raptor88 18 6,650 Feb-27-2017, 02:44 AM
Last Post: Raptor88

Forum Jump:

Users browsing this thread: 1 Guest(s)