Python Forum
Why does my Switch trigger all Cases?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why does my Switch trigger all Cases?
#7
(Apr-09-2018, 09:21 AM)IAMK Wrote: However, do you know why my code was printing all 3?
Function calls in return dictionary will trigger all call.
Could do it like this.
def f_3OAK():
    print("Hello1.")

def f_4OAK():
    print("Hello2.")

def f_5OAK():
    print("Hello3.")

def case(s_Input):
    return {
        '3OAK': f_3OAK,
        '4OAK': f_4OAK,
        '5OAK': f_5OAK
    }[s_Input]

while True:
    case(input("\nPlease enter the win you wish to search for: "))()
Reply


Messages In This Thread
Why does my Switch trigger all Cases? - by IAMK - Apr-08-2018, 03:44 PM
RE: Why does my Switch trigger all Cases? - by IAMK - Apr-08-2018, 06:16 PM
RE: Why does my Switch trigger all Cases? - by IAMK - Apr-09-2018, 09:21 AM
RE: Why does my Switch trigger all Cases? - by snippsat - Apr-09-2018, 11:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to trigger for loop after while quest 2 1,541 Mar-22-2022, 11:34 PM
Last Post: quest
  best way to use switch case? korenron 8 3,043 Aug-18-2021, 03:16 PM
Last Post: naughtyCat
  Pandas, How to trigger parallel loop Mekala 4 2,769 Oct-29-2020, 12:58 PM
Last Post: Mekala
  Uses cases for list comprehension (encountered while doing PyBite #77) Drone4four 3 2,809 Sep-25-2020, 12:14 PM
Last Post: ndc85430
  Iterating through lists with different letter cases fatherted99 2 1,896 Jun-07-2020, 01:22 PM
Last Post: deanhystad
  How do I do this? Switch Case? mstichler 4 2,597 Jun-05-2020, 10:27 AM
Last Post: snippsat
  How to trigger python script twice a day SriMekala 1 3,947 Aug-30-2019, 01:31 AM
Last Post: scidam
  Decorator staticmethod Use Cases Devarishi 3 2,665 May-20-2019, 04:27 AM
Last Post: Devarishi
  switch limitations MuntyScruntfundle 3 2,400 Jan-27-2019, 06:11 PM
Last Post: aakashjha001
  How to trigger a function by clicking the left mouse click? HelloBoyz 1 9,448 Jun-29-2017, 09:43 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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