Mar-21-2018, 11:40 AM
Hi. I am a guy with a Java background learning Python. I wrote a small text-based game. I created a __main__ class and a class called CharacterCreation. The second has two functions in it. Weird thing is, if I launch the program I am able to fire the first function, but an error occurs before the second is fired , self.class_strenght() . Could anyone please advice what Iam doing wrong?
This is my console output:
This is my __main__ :
This is my characterCreation file:
This is my console output:
Quote:What is your name?d---> error is where self.class_strenght() should be called
My name is d
Nice to meet you d !
What class are you? You can choose warrior, priest, mage or thief!thief
thief
are you sure? Yes or No?yes
Error
This is my __main__ :
1 2 3 4 5 6 7 |
import characterCreation def main(): characterCreation.CharacterCreation().controller() if __name__ = = "__main__" : main() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#Character creation: import random import time class CharacterCreation( object ): def charCreate( self ): protagonist_name = input ( 'What is your name?' ) print ( 'My name is' , protagonist_name) time.sleep( 1 ) print ( 'Nice to meet you' , protagonist_name, '!' ) time.sleep( 1 ) flag = 'no' ; while (flag = = 'no' ): protagonist_class = input ( 'What class are you? You can choose warrior, priest, mage or thief!' ) prot = protagonist_class.lower() print (prot) while (prot ! = 'warrior' and prot ! = 'priest' and prot ! = 'thief' and prot ! = 'mage' ): print ( 'You did not pick a class, please try again' ) protagonist_class = input ( 'What class are you? You can choose warrior, priest, mage or thief!' ) prot = protagonist_class.lower() flag = input ( 'are you sure? Yes or No?' ).lower() def class_strenght( self ): prot = '' if prot = = 'warrior' : power = random.randint( 10 , 18 ) print ( 'Your strenght is' , power) elif prot = = 'priest' : power = random.randint( 8 , 16 ) print ( 'Your strenght is' , power) elif prot = = 'thief' : power = random.randint( 6 , 14 ) print ( 'Your strenght is' , power) elif prot = = 'mage' : power = random.randint( 4 , 12 ) print ( 'Your strenght is' , power) else : print ( 'Error' ) def controller( self ): self .charCreate() self .class_strenght() |