Python Forum
switch case with range
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
switch case with range
#1
I'm new to python and working on some homework.

def letter(i):
    switcher={
            0:'a',
            1:'b',
            2:'c'
            }
    return switcher.get(i,"Invalid")
Output:
letter(0) -> 'a' letter(2) -> 'c' letter(3) -> 'Invalid'
Can I use a range in the case#? something like below, I tried different ways but didn't work.
            0:'a',
            1:'b',
         2..5:'c'
I also tried

range(2,5):'c' 


didn't work.

Is there easy way to do that?

Thanks,
Reply


Messages In This Thread
switch case with range - by jun - Feb-26-2019, 09:54 PM
RE: switch case with range - by scidam - Feb-26-2019, 11:04 PM
RE: switch case with range - by ichabod801 - Feb-27-2019, 04:48 AM
RE: switch case with range - by scidam - Feb-27-2019, 05:35 AM

Forum Jump:

User Panel Messages

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