Build an RPG character - Build an RPG Character

Tell us what’s happening:

My case test 10 is not passing. Can someone help me? The logic is correct, the output is matching the test string but the last test case is not passing

Your code so far

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

    character_string=name
    for key in ['STR', 'INT', 'CHA']:
        stat = stats[key]
        character_string += f'\n{key} {full_dot*stat}{empty_dot*(10-stat)}'

    return character_string  

print(create_character("ren",4,2,1))
test_str = 'ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○'
print(f"{test_str}")










Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36

Challenge Information:

Build an RPG character - Build an RPG Character
https://www.freecodecamp.org/learn/full-stack-developer/lab-rpg-character/build-an-rpg-character

What is test 10? Which specific part of your code do you think satisfies this test?

your issue is with this user story

  • If the character name is longer than 10 characters, the function should return The character name is too long.

"When create_character is called with valid values it should output the character stats as required " this is the test case

Which specific part of your code do you think satisfies this test?

Please answer both questions I asked.

this part I think is causing problem

that part is not causing problems, focus on what’s inside the function

can you answer the question about which part of your function is dealing with that user story?

    character_string=name
    for key in ['STR', 'INT', 'CHA']:
        stat = stats[key]
        character_string += f'\n{key} {full_dot*stat}{empty_dot*(10-stat)}'

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

1 Like

Tracing back from here, here is a valid test case

print(create_character("catanddogs",4,2,1))

Is the correct name printed in the output?

yes the name is printing correct in the output as the test case print(create_character("catanddogs",4,2,1)) this is giving the character name too long which is also correct, but case test is not passing

No, that is not correct.

yeah I changed it thank you it is now done

@bluekirat i have the same issue can you please tell me how you solved it?

hi @shrashti please create your own post to ask your question

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

removed by moderator

The following code passed for me
removed by moderator

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like