Build an RPG Character - Build an RPG Character

Tell us what’s happening:

I am lost. Until I made a last change, I had passed 3 tests, but now none, although I did not change anything for those tests I had passed.

Your code so far

full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
    if (name) is not str:
        return "The character name should be a string"
    if (name) == " ":
        return "The character should have a name"
    if (name.count) > 10:
        return "The character name is too long"
    if " " in name:
        return "The character name should not contain spaces"
    if (strength) is not int or (intelligence) is not int or (charisma) is not int:
        return "All stats should be integers"
    if (strength) < 1 or (intelligence) < 1 or (charisma) < 1:
        return "All stats should be no less than 1"
    if (strength) > 4 or (intelligence) > 4 or (charisma) > 4:
        return "All stats should be no more than 4"
    if total(strength + intelligence + charisma) != 7:
        return "The character should start with 7 points"
    return: 
        "name" + "\n"
        result += "STR{strength * full_dot}{(10 - strength * empty_dot}"
        result +=  "INT{intelligence * full_dot}{(10 - intelligence) * empty_dot}"
        result += "CHA{charisma * full_dot}{(10 - charisma) * empty_dot}"




Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3.1 Safari/605.1.15

Challenge Information:

Build an RPG Character - Build an RPG Character

Traceback (most recent call last):
  File "main.py", line 20
    return: 
          ^
SyntaxError: invalid syntax

aren’t you seeing this in the terminal?

Yes, I changed line 20 into: else: then the expected results in 4 lines

But then I pass only 3 tests (#1, 2, 5), all other tests fail. Not sure why

Maybe I should restart a new help session so you see my latest code?

so you see how it’s pointing to the : next to return? that’s invalid syntax

please don’t create a new topic, post your updated code in this topic

When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

There was no syntax error whatsoever on the right-hand side, only an empty table, which made me believe that my code was correct. But meanwhile I did change the code to a previous version when I passed 3 tests and failed all other tests.

Here is the latest code

full_dot = '●'

empty_dot = '○'

def create_character(name, strength, intelligence, charisma):

if (name) is not str:

return "The character name should be a string"

if (name) == " ":

return "The character should have a name"

if (name.count) > 10:

return "The character name is too long"

if " " in (name):

return "The character name should not contain spaces"

if (strength) is not int or (intelligence) is not int or (charisma) is not int:

return "All stats should be integers"

if (strength) < 1 or (intelligence) < 1 or (charisma) < 1:

return "All stats should be no less than 1"

if (strength) > 4 or (intelligence) > 4 or (charisma) > 4:

return "All stats should be no more than 4"

if (strength + intelligence + charisma) != 7:

return "The character should start with 7 points"

else:

"name" + "\\n"

        result += "STR{strength \* full_dot}{(10 - strength \* empty_dot}"

        result +=  "INT{intelligence \* full_dot}{(10 - intelligence) \* empty_dot}"

        result += "CHA{charisma \* full_dot}{(10 - charisma) \* empty_dot}"

result = create_character('ren',4,2,1)

print (result)

I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Unfortunately your indentation got mangled when you tried to post your code.

I’ve provided instructions of formatting.

Do you need the else: clause?

Here are some debugging steps you can follow. Focus on one test at a time:

  1. Are there any errors or messages in the console?
  2. What is the requirement of the failing test?
  3. Check the related User Story and ensure it’s followed precisely.
  4. What line of code implements this?
  5. What is the result of the code and does it match the requirement? (Write the value of a variable to the console at that point in the code if needed.)

If this does not help you solve the problem, please reply with answers to these questions.

Do I need the else clause, I assume yes. Whenever any of the if clauses applies, it stops there. If they do not apply, then we go for steps 11-12.

question 1: no error message in the console. When I click on console, it repeats the instructions of the failed tests, does not mention any error message.

question 2: i read again the requirements of the failing tests, and my code does test what needs to be tested with the required results.

question 3: I actually coded reading only the user story.

question 4: see 3

question 5: the result of the code should match the requirements but the test fails. By the way, if I change for instance the code of step 3, the tests of other steps (unrelated to step 3) which had passed all of a sudden fail. So I start wondering whether the system works properly.

Can you post the latest version of your code?

Make sure to format it after you paste it and before you hit “reply” so the formatting stays intact.

full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
    if (name) is not str:
        return "The character name should be a string"
    if len(name) == 0:
        return "The character should have a name"
    if (name.count) > 10:
        return "The character name is too long"
    if " " in (name):
        return "The character name should not contain spaces"
    if (strength) is not int or (intelligence) is not int or (charisma) is not int:
        return "All stats should be integers"
    if (strength) < 1 or (intelligence) < 1 or (charisma) < 1:
        return "All stats should be no less than 1"
    if (strength) > 4 or (intelligence) > 4 or (charisma) > 4:
        return "All stats should be no more than 4"
    if (strength + intelligence + charisma) != 7:
        return "The character should start with 7 points"
    else:
        "name" + "\n"
        result += "STR{strength * full_dot}{(10 - strength * empty_dot}"
        result += "INT{intelligence * full_dot}{(10 - intelligence) * empty_dot}"
        result += "CHA{charisma * full_dot}{(10 - charisma) * empty_dot}"
result = create_character('ren',4,2,1)
print (result)
1 Like

you are missing the return for the case in which all input is acceptable, where is the return for that?

What does your function return if all validation tests pass?

full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
    if (name) is not str:
        return "The character name should be a string"
    if len(name) == 0:
        return "The character should have a name"
    if (name.count) > 10:
        return "The character name is too long"
    if " " in (name):
        return "The character name should not contain spaces"
    if (strength) is not int or (intelligence) is not int or (charisma) is not int:
        return "All stats should be integers"
    if (strength) < 1 or (intelligence) < 1 or (charisma) < 1:
        return "All stats should be no less than 1"
    if (strength) > 4 or (intelligence) > 4 or (charisma) > 4:
        return "All stats should be no more than 4"
    if (strength + intelligence + charisma) != 7:
        return "The character should start with 7 points"
    else:
        return "name"
        return "STR{strength * full_dot}{(10 - strength * empty_dot}"
        return "INT{intelligence * full_dot}{(10 - intelligence) * empty_dot}"
        return "CHA{charisma * full_dot}{(10 - charisma) * empty_dot}"

same 3 tests pass, all others fail

you are returning a string that say “name”, is that what you want to return?

full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
    if (name) is not str:
        return "The character name should be a string"
    if len(name) == 0:
        return "The character should have a name"
    if (name.count) > 10:
        return "The character name is too long"
    if " " in (name):
        return "The character name should not contain spaces"
    if (strength) is not int or (intelligence) is not int or (charisma) is not int:
        return "All stats should be integers"
    if (strength) < 1 or (intelligence) < 1 or (charisma) < 1:
        return "All stats should be no less than 1"
    if (strength) > 4 or (intelligence) > 4 or (charisma) > 4:
        return "All stats should be no more than 4"
    if (strength + intelligence + charisma) != 7:
        return "The character should start with 7 points"
    else:
        print ("name")
        print ("STR{strength * full_dot}{(10 - strength * empty_dot}")
        print ("INT{intelligence * full_dot}{(10 - intelligence) * empty_dot}")
        print ("CHA{charisma * full_dot}{(10 - charisma) * empty_dot}")

Same results as before: 3 tests pass, all others fail

Your function needs to return something! You are just printing to the console.

I suggest you start small. Copy your code into a local file so you can paste it back incrementally.

Then add back just the first if statement. Test by calling the function inside a print passing in a number for the name rather than a string. Do you get the expected error message?

If not, fix it until you do get what’s expected, then move on to the next if statement, etc, etc.

Also, please understand that if your code hits a return statement, it stops processing. You don’t need the else.