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

Dani AI

Generated

A short, practical follow-up that ties together the fixes already posted by , and , and gives a cleaner, more maintainable direction.

The root problems you hit were: a missing string join in the original print (fixed by ), comparing a text input to an integer (see ), and loading profession attributes without assigning them to the player (see ). Rather than patching those one at a time, consider representing professions as small immutable objects and mapping user choices to those objects — it keeps code readable and makes it trivial to attach the chosen profession to a character.

Example (Python 3 style; modernizes the old raw_input approach):

from dataclasses import dataclass

@dataclass(frozen=True)
class Profession:
    name: str
    strength: int
    pilot: int
    intel: int
    stamina: int

STAR = Profession("Starfighter", 20, 55, 40, 35)
CHOICES = {"1": STAR, "2": Profession("Chief Diplomat",45,20,50,35)}

Then handle input defensively and attach the chosen Profession to a Character object rather than trying to import things mid-function:

choice = input("Choose your class: ").strip()
prof = CHOICES.get(choice)
if not prof:
    print("Invalid choice — try 1..2")
else:
    # assign to your player object, e.g. player.profession = prof
    print(f"You are now a {prof.name} and have been equipped...")

Practical tips:

  • Prefer import at the module top (avoid importing inside if blocks).
  • Use .strip() and validate input; compare strings to strings (or convert explicitly once).
  • Bind profession data to a player via composition (player.profession) so stats come from one place.
  • If you stick with Python 2 for now, raw_input() behaves like input() in Python 3, but consider porting — f-strings and dataclasses simplify this design a lot.

These changes address the immediate bugs and set a clearer structure for adding methods, saving state, or expanding classes later (as suggested).

Recommended Answers

All 13 Replies

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

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 +

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
 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':

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!!

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

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

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

If your character picks starfighter, then those initial values have to be assigned to your character.

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

You can do it this way:

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

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

result = text(chara)

print result

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.