Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PyPackMenuClass
#python 3.6.9 #PyPackMenuClass: example of switch using class where menu items are defined outside the menu class #this code is created by Rezaul Hoque on April 14,2022. #contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com #note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; class SetMenu: def __repr__(): s1=f'Default package has 2 parathas, 1 scrambled egg and 1 chai. It costs Tk 50.\n' return s1 class Package1: def __repr__(): s2=f'Package 1 has 2 rotis, 1 dal and 1 coffee. It costs Tk 80.\n' return s2 class Package2: def __repr__(): s3=f'Package 2 has 3 slices of bread, jelly, banana and chai. It costs Tk 40.\n' return s3 class Package3: def __repr__(): s4=f'Package 3 has 1 plate of khichri.It costs Tk 60.\n' return s4 class Menu(object): def pack_0(self): print(f'{SetMenu.__repr__()}') def pack_1(self): print(f'{Package1.__repr__()}') def pack_2(self): print(f'{Package2.__repr__()}') def pack_3(self): print(f'{Package3.__repr__()}') def getMethod(self,op): calmethod="pack_"+str(op) method=getattr(self,calmethod,lambda :'Insert number between 0 and 4') return method() t=Menu() print(" (0)Set Menu (1)Pack1 (2)Pack2 (3)Pack3") choice=int(input("Select\n")) print(t.getMethod(choice))
run
|
edit
|
history
|
help
0
RemoveDuplication
Hello,world
https://rextester.com/HYVN80193
snake water gun game
Get count
PyList
Java adding 2 num
print path module python
Python My G(ame,uess)
E