Nov-07-2019, 07:22 PM
(This post was last modified: Nov-07-2019, 07:22 PM by kozaizsvemira.)
(Nov-07-2019, 07:06 PM)newbieguy Wrote:Quote:There is no switch/case statement in Python. Use if/elif instead or a data structure. You did use a data structure, but I would do it this way:Yea I know it,I wanted to know way that is being similar like switch/case,because this is very useful option.
I've never worked with switches never thought about it, but found a solution
a = int(input('First num:')) b = int(input('Second num:')) def add(): return a + b def subtract(): return a - b # Your Input choice = input('Choose:') choices = { '1': add(), '2': subtract() } result = choices.get(choice, 'default') print(result)