Build an RPG Character - Build an RPG Character

Tell us what’s happening:

Hello,
I’m having and issue with test lines 17-19. I can’t seem to figure out the proper answer this exercise wants me to have. I have noticed that with coding / programming, there are multiple ways to achieve a goal but for the labs, this doesn’t seem to be the case.

I skipped a few steps to make a little bit more process but I am circling back around.

Your code so far

full_dot = '●'
empty_dot = '○'

#Charcater Info
character_name = 'Ace'

strength = 4
charisma = 2
intelligence = 1

STR = strength
CHA = charisma
INT = intelligence
stats = strength, charisma, intelligence

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

#Validates charcater name
#2-9
    if not isinstance(character_name,str):
        return 'The character name should be a string'
    if character_name == "":
        return 'The character should have a name'
    if len(character_name) > 10:
        return 'The character name is too long'
    if ' ' in character_name:
        return 'The character name should not contain spaces'
#Validates stats
#10-16
    if not isinstance(strength, int):
        return 'All stats should be integers'
    if not isinstance(charisma, int):
        return 'All stats should be integers'
    if not isinstance(intelligence, int):
        return 'All stats should be integers'
#-------------------------------------------------------------  
    if strength < 1:
        return 'All stats should be no less than 1'
    if charisma < 1:
        return 'All stats should be no less than 1'
    if intelligence < 1:
        return 'All stats should be no less than 1'
#-------------------------------------------------------------  
    if strength > 4:
        return 'All stats should be no more than 4'
    if charisma > 4:
        return 'All stats should be no more than 4'
    if intelligence > 4:
        return 'All stats should be no more than 4'
#-------------------------------------------------------------  
    if not isinstance((create_character, stats), int) == 7:
        return 'The character should start with 7 points'
    else:
        pass
        
#Test with print() instead of return below:

print(character_name)
print('STR','●'*(strength) + '○'*(10-strength))
print('INT','●'*(intelligence) + '○'*(10-intelligence))
print('CHA','●'*(charisma) + '○'*(10-charisma))

Your browser information:

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

Challenge Information:

Build an RPG Character - Build an RPG Character

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-rpg-character/67d83df6f82eda3868dd2a84.md at main · freeCodeCamp/freeCodeCamp · GitHub

Welcome to the forum @romello_henderson,

Please review the followiing theory lecture about how to use isinstance(). You can check one variable against one or more types, but you cannot check multiple variables against a type. What does this method return? Does it return an integer?

Understanding Variables and Data Types - How Do the type() and isinstance() Functions Work? | Learn | freeCodeCamp.org

These values should be passed to the function in a function call like this: create_character('ren',4,2,1) or create_character('hello',3,2,2)

Happy coding

Well, I cannot use this to find a solution because I can only use (2) arguments in a isinstance() function. When I try to use the:

create_character(character_name,strength,intelligence,charisma) method, it says It called for 2 arguements and got 4.

So then, I tried using “stats” to combine the 3 together and it’s still not working. I understand I’m trying to compare a string (stats) to a integer but I struggling to find the alternative…

create_character is the name of the function you are writing code in and create_character(character_name,strength,intelligence,charisma) is that function’s definition.

When you call the function like this: create_character('Flash',1,3,3), can you say what the value of strength will be? intelligence? charisma? These are the character’s stats. How do you get the total value of those stats?

Ok, I think I’m following… If I input it like that I will always get False right?

isinstance() returns either True or False, yes.

Following the format that I created in the def () function is how I know what my “STR = strength” value is.

create_character(character_name,strength, charisma, intelligence):

But when I trying to verify all of that at the same time is where I think I’m getting lost. I know i can use the isinstance() function but that is just validating the boolean value… But I think I got test 17 fixed.

Can I share my updated code?

Please post your updated code formatted as follows:

There are two ways you can format your code to make it easier to read and test:

  1. After you copy/paste your code into the editor, select it by dragging your cursor over it then click the (</>) button in the toolbar to automatically wrap your code in backticks. (You can click on the animated demo image below to enlarge it.)

  1. Manually add three backticks on a new line above your code and on a new line after your code. Note that a backtick is NOT the same as a single quote('). To find the backtick key on your keyboard, see this post.

To see changes to your post as you make them, you can click the (M+) button on the toolbar to bring up the rich text editor:

full_dot = '●'
empty_dot = '○'

#Charcater Info
character_name = 'Ace'

strength = 4
charisma = 2
intelligence = 1

STR = strength
CHA = charisma
INT = intelligence
stats = strength + charisma + intelligence

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

#Validates charcater name
#2-9
    if not isinstance(character_name,str):
        return 'The character name should be a string'
    if character_name == "":
        return 'The character should have a name'
    if len(character_name) > 10:
        return 'The character name is too long'
    if ' ' in character_name:
        return 'The character name should not contain spaces'
#Validates stats
#10-16
    if not isinstance(strength, int):
        return 'All stats should be integers'
    if not isinstance(charisma, int):
        return 'All stats should be integers'
    if not isinstance(intelligence, int):
        return 'All stats should be integers'
#-------------------------------------------------------------  
    if strength < 1:
        return 'All stats should be no less than 1'
    if charisma < 1:
        return 'All stats should be no less than 1'
    if intelligence < 1:
        return 'All stats should be no less than 1'
#-------------------------------------------------------------  
    if strength > 4:
        return 'All stats should be no more than 4'
    if charisma > 4:
        return 'All stats should be no more than 4'
    if intelligence > 4:
        return 'All stats should be no more than 4'
#-------------------------------------------------------------  
    if strength + intelligence + charisma != 7:
        return 'The character should start with 7 points'
    else:
        pass 
        
#Test with print() instead of return below:

print(character_name)
print('STR','●'*(strength) + '○'*(10-strength))
print('INT','●'*(intelligence) + '○'*(10-intelligence))
print('CHA','●'*(charisma) + '○'*(10-charisma))

# Ace
# STR ●●●●○○○○○○
# INT ●○○○○○○○○○
# CHA ●●○○○○○○○○

I think my code is really long and a bit redundant. Once I get the code completed, would you be willing to help me understand how to make this more concise and polished?

You will need to return a final string to pass the tests.

Just wrap your function call in print to see what your function returns in the console:

print(create_character('ren',4,2,1))

You can refer to Test #18 to see what that string should look like.

I was able to pass test 18 but I still don’t understand what I did…

full_dot = '●'
empty_dot = '○'

#Charcater Info
character_name = 'Ace'

strength = 4
charisma = 2
intelligence = 1

STR = strength
CHA = charisma
INT = intelligence
stats = strength + charisma + intelligence

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

#Validates charcater name
#2-9
    if not isinstance(character_name,str):
        return 'The character name should be a string'
    if character_name == "":
        return 'The character should have a name'
    if len(character_name) > 10:
        return 'The character name is too long'
    if ' ' in character_name:
        return 'The character name should not contain spaces'
#Validates stats
#10-16
    if not isinstance(strength, int):
        return 'All stats should be integers'
    if not isinstance(charisma, int):
        return 'All stats should be integers'
    if not isinstance(intelligence, int):
        return 'All stats should be integers'
#-------------------------------------------------------------  
    if strength < 1:
        return 'All stats should be no less than 1'
    if charisma < 1:
        return 'All stats should be no less than 1'
    if intelligence < 1:
        return 'All stats should be no less than 1'
#-------------------------------------------------------------  
    if strength > 4:
        return 'All stats should be no more than 4'
    if charisma > 4:
        return 'All stats should be no more than 4'
    if intelligence > 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 'ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○'

#Test with print() instead of return below:

Do you have a question?

What is it that you don’t understand?

Why do I use the provided string (ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○) instead of having a “string” generated by the logic that is within the program?

Example of what was in my code:

print(character_name)

print(‘STR’,‘●’*(strength) + ‘○’*(10-strength))

print(‘INT’,‘●’*(intelligence) + ‘○’*(10-intelligence))

print(‘CHA’,‘●’*(charisma) + ‘○’*(10-charisma))

Are you talking about this line of code?

return 'ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○'

You’re asking why you have this line of code?

Or why it works to solve the challenge?

Why does this work, yes.

Well, it does not pass all of the tests, so it does not work.

// running tests
19. When create_character is called with valid values it should output the character stats as required.
// tests completed

What you’ve done is called “hardcoding”

It looks like you have hard-coded conditionals or variables that check for specific expected values. That is not solving this problem in the general case. Imagine if you were given different input values. Would your code be able to solve those problems?

To find out more about what hard-coding is or about why it is not suitable for solving coding questions, please read this post: Hard-coding For Beginners

Let us know if you have a question about how to make your code more flexible.