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
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.
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.
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)
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}"
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}")
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.