Python 3: Calling a function from its class to simulate a switch statement not working -


i writing program simulation game of variant on rock paper scissors game. in main function outputting interface , trying call method defined within acts switch statement. getting: "makesel() missing 1 required positional argument: 'self'" typeerrors have scoured web hints yet cannot find have helped. have tried change "makesel()" "main.makesel()" gives me main undefined.


class main:      def makesel(self):         selection = input()         if(selection == 1):             return stupidbot('stupidbot')         elif(selection == 2):             return randombot('randombot')         elif(selection == 3):             return iterativebot('iterativebot')         elif(selection == 4):             return lastplaybot('lastplaybot')         elif(selection == 5):             return mybot('mybot')         elif(selection == 6):             return humanplayer('humanplayer')         else:             print('invalid selection, please try again.  enter 1, 2, 3, 4, 5, or 6')             makesel()      print('')     print('welcome rock-paper-scissors-lizard-spock game!')     print('')     print('please select 2 players, enter 1, 2, 3, 4, 5, or 6')     print('  (1) -> stupidbot')     print('  (2) -> randombot')     print('  (3) -> iterativebot')     print('  (4) -> lastplaybot')     print('  (5) -> mybot')     print('  (6) -> humanplayer')      p1 = makesel()     p2 = makesel() 

i hoping able shed light on issue experiencing.

to fix immediate but, change makesel() self.makesel(). self isn't implicitly passed method calls in python, unlike other languages. mean return self.makesel(), think.

also, think want loop in mainsel(). you're recursively calling mainsel() work lot loop fill call stack.

class main:      def makesel(self):         while true             selection = input()             if(slection == 1):                 return stupidbot('stupidbot')             elif(slection == 2):                 return randombot('randombot')             elif(selection == 3):                 return iterativebot('iterativebot')             elif(selection == 4):                 return lastplaybot('lastplaybot')             elif(selection == 5):                 return mybot('mybot')             elif(selection == 6):                 return humanplayer('humanplayer')             else:                 print('invalid selection, please try again.  enter 1, 2, 3, 4, 5, or 6') 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -