0

Hello,

I am wondering what I am missing. Keep getting a syntax error at the chara on Line 8.....

def main():

    print('WELL! Hello. Thank you for choosing your path to'\
          'righteousness! bahahaha!')
    chara = raw_input(str('Please input your character name: '))

    #print the welcome for user
    print('Ok,'chara,'This is just protype son but soon!...2years and pending')


main()

Edited by mkweska

8
Contributors
13
Replies
77
Views
4 Years
Discussion Span
Last Post by Schol-R-LEA
Featured Replies
  • 2

    For future reference, the error was eliminated because you added the plus signs. Also, include the entire error message in the future. print('Ok,'chara, print('Ok, '+ chara + Read More

  • 3

    > classChosen = raw_input('Choose your class: ') > if classChosen == int(1): This will never be true as classChosen is string, not integer. It is clearer also not to use int without purpose. classChosen = raw_input('Choose your class: ') if classChosen == '1': Read More

  • Perhaps it would make more sense to start with a parent class, Profession, which would have the various attributes in common to all the subclasses: class Profession(object): def __init__(self, name, strength, pilot, intel, stamina): self.strength = strength self.pilot = pilot self.intel = intell slef.stamina = stamina # other methods common … Read More

0

Ok, well I figured it out...changed it from raw_input(str( to just raw_input()

def main():

    print('WELL! Hello. Thank you for choosing your path to'\
          'righteousness! bahahaha!')
    chara = raw_input('Please enter your charcter name: ')

    #print the welcome for user
    print('Ok, '+ chara +', this is just protype son but soon!...2years'\
          'and pending.....')


main()
2

For future reference, the error was eliminated because you added the plus signs. Also, include the entire error message in the future.

print('Ok,'chara,
print('Ok, '+ chara +

Edited by woooee

0

Thanks for that solid information! I have now stumbled upon another problem here.. It has to do with loading classes from another py file and then displaying a message. Instead of displaying the if: it goes to the else: and prints 'Choose AGAIN!'

I feel it may have to do with the way I loaded the classes...not 100% sure though.. Tired adding a variable to the raw_input from the classChosen to no avail...

main.py

def main():


     print('WELL! Hello. Thank you for choosing your path to '\
           'righteousness! bahahaha!')
     chara = raw_input('Please enter your charcter name: ')

    #print the welcome for user
     print('Ok, '+ chara +', choose your class type and set your stage')
     print('and prepare for adventure filled with lots of candy and mountains')

     print('****************')
     print('/   classes    /')
     print('****************')

     print('1 Starfighter')
     print('2 Chief Diplomat')
     print('3 Smuggler')
     print('4 Architect')
     print('5 Medic')

     classChosen = raw_input('Choose your class: ')

     if classChosen == int(1):
          from professions import starfighter
          print('You are now a Starfighter and have been equipped')
          print('with a Delta Hawk to begin your travels.')
     else:
          print('Choose AGAIN!')


main()

profession.py

def starfighter():
    strength = 20
    pilot = 55
    intelli = 40
    stamina = 35

def chiefdiplomat():
    strength = 45
    pilot = 20
    intelli = 50
    stamina = 35
3
 classChosen = raw_input('Choose your class: ')

if classChosen == int(1):

This will never be true as classChosen is string, not integer. It is clearer also not to use int without purpose.

 classChosen = raw_input('Choose your class: ')
 if classChosen == '1':

Edited by pyTony

0

Thanks for the info pyTony! Yeah I have no idea why I put int(1) I figured after "if classChosen == 1:" did not work it could possibly be int(). But I see exactly what you did! You put the one into quotes to designate it a string... Thanks alot for your help!!

0

and... the module profession.py returns nothing!
so your player will not have any of those properties.

0

What would I need to return from profession.py? It just loads the attributes...do I still need to return the attributes to main?

0

the values in those two function have to be returned, in order to assign them to variables in main:

def starfighter ():
    strength = 20
    pilot = 55
    intelli = 40
    stamina = 35
    return strength, pilot, inteli, stamina
def chiefdiplomat ():
    strength = 45
    pilot = 20
    intelli = 50
    stamina = 35
    return strength, pilot, inteli, stamina
0

Would there be a way to assign all the attribute variables into a single variable for starfighter? Would it work as a list possibly?

1

You can do it this way:

class starfighter():
    strength = 20
    pilot = 55
    intelli = 40
    stamina = 35

print(starfighter.strength)  # 20
print(starfighter.intelli)   # 40
0
def text(your_text):
    return your_text
chara = raw_input("Please input your character name: ")

result = text(chara)

print result
2

Perhaps it would make more sense to start with a parent class, Profession, which would have the various attributes in common to all the subclasses:

class Profession(object):
    def __init__(self, name, strength, pilot, intel, stamina):
        self.strength = strength
        self.pilot = pilot
        self.intel = intell
        slef.stamina = stamina

    # other methods common to all the subclasses would go here

class Starfighter(Profession):
    def __init__(self, name, strength = 20, pilot = 55, intel = 40, stamina = 35):  # defaults - can be overridden
        Profession.init__(self, name, strength, pilot, intel, stamina)

    # methods specific to Starfighters

class Diplomat(Profession):
    def __init__(self, name strength = 45, pilot = 20, intel = 50, stamina = 35):  # defaults - can be overridden
        Profession.init__(self, name, strength, pilot, intel, stamina)

    # methods specific to Diplomats

# etc. - classes for other professions here

You then could simply declare your characters as being of the given class:

defaultPilot = Starfighter("John Doe")
betterPilot = Starfighter("Luke Skywalker", pilot = 75)  # using custom values for the attributes

Hopefully, this will get you going. Let us know if you need more help on this.

Edited by Schol-R-LEA

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.