can anyone help me how to solve this? thank you!!!
Your code so far
full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
# Name validation
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 validation
stats = [strength, intelligence, charisma]
for stat in stats:
if not isinstance(stat, int):
return 'All stats should be integers'
if not(1 <= stat <= 4):
return 'All stats should be no less than 1 and no more than 4'
if sum(stats) != 7:
return 'The character should start with 7 points'
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
I think the problem is the third if statement for name. you’re supposed to check for space, but it’s an empty string which is considered to exist in every string and it keeps stopping there before ever reaching the integer check. Hope it helps
You do… That’s what’s stopping you from reaching the stats check at all… you’re not checking for space but an empty string which is always true and returns prematurely. Try printing the function and you’ll see… You passed Step 4 somehow, but IF ONLY you made that small change, you’d pass Step 5… Step 6 and 7 is failing because you ignored the instructions and combined the statements on your own. You gotta follow it exactly as told or it’d fail. If you’re still not convinced, I can’t help further. All the best tho.
freeCodeCamp accepted my step 1 - 4 coding. Only the step 5 - 10 that they do not accept. I cannot move on from this challenge. I’m stuck here for hours already. Help me please.
The problem is that you are copying code you find and not really working to understand what you’re doing. You may want to go back to previous lessons and make sure you really understand the material.
If you have a question about something you don’t understand, you should ask in the forum.
Of course, everyone working on this is just a beginner.
You way of learning or your way of easily passing the labs?
You should never be copying code and putting it in the editor here. You should definitely be searching for resources on how to use a particular function, or how to do something.
“python how to check type”
“python type()”
“python how to loop”
Read how to use the tools, then implement it yourself.
It’s not accepting code you copied, but why can’t you figure it out? It’s because you haven’t been learning.
To actually solve this take this advice:
You need to print the function to see the output
print(create_character("test a long name with spaces", 0, 2, 3))
Use print()
Use print() in your code to check on variables and test statements. You have no print statements at all in your code so you are totally blind to anything that’s happening
It’s this line “ if “” in name:
return ‘The character name should not contain spaces’“. Empty spaces are found in all strings so that it will always be true. Swap "" for " " and your validation will behave.