Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beginners question
#1
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:
Quote:What is your name?d
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
---> error is where self.class_strenght() should be called

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()        
    
        
Reply


Messages In This Thread
Beginners question - by Youmanity - Mar-21-2018, 11:40 AM
RE: Beginners question - by Windspar - Mar-21-2018, 12:49 PM
RE: Beginners question - by Youmanity - Mar-21-2018, 01:10 PM
RE: Beginners question - by Windspar - Mar-21-2018, 01:37 PM
RE: Beginners question - by Youmanity - Apr-08-2018, 07:02 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020