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 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__ :
import characterCreation def main(): characterCreation.CharacterCreation().controller() if __name__ == "__main__": main()This is my characterCreation file:
#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()