I’m passing some tests and failing some but when I call the function with arguments it shows the right results.
Your code so far
full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
if not isinstance(name, str):
print('The character name should be a string')
if not name:
print('The character should have a name')
if len(name) >10:
print('The character name is too long')
if ' ' in name:
print('The character name should not contain spaces')
stats = [strength, intelligence, charisma]
for stat in stats:
if not isinstance(stat, int):
print('All stats should be integers')
if stat < 1:
print('All stats should be no less than 1')
if stat > 4:
print('All stats should be no more than 4')
if sum(stats)!= 7:
print('The character should start with 7 points')
create_character('ren', 4, 2, 1)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
When I call your create_character function with print I am returning None in the terminal indicating to me that the code is not written properly yet you may still have work to do with it
my terminal is blank. doesn’t show any errors. But when I try changing the arguments to test the conditions I’m getting the right outputs. is there a terminal setting that may be messed up on my end?
If i edit your code and change ‘ren’ to a number (AKA int or integer) in your create_character call I return in the terminal way more than the test is asking for.
if not isinstance(name, str):
print('The character name should be a string')
elif not name:
print('The character should have a name')
elif len(name) >10:
print('The character name is too long')
elif ' ' in name:
print('The character name should not contain spaces')
stats = \[strength, intelligence, charisma\]
for stat in stats:
if not isinstance(stat, int):
print('All stats should be integers')
if stat < 1:
print('All stats should be no less than 1')
elif stat > 4:
print('All stats should be no more than 4')
elif sum(stats)!= 7:
print('The character should start with 7 points')
I copy pasted the most recent code block you sent and then formatted it according to the screenshot you shared and recieve an error in the terminal relating to your stats variable. Can you copy and paste the entirety of your code block and insert it into the comments to ensure I have what you have as you did not report seeing this error. this is what I have in the code right now.
full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
if not isinstance(name, str):
print('The character name should be a string')
elif not name:
print('The character should have a name')
elif len(name) >10:
print('The character name is too long')
elif ' ' in name:
print('The character name should not contain spaces')
stats = \[strength, intelligence, charisma\]
for stat in stats:
if not isinstance(stat, int):
print('All stats should be integers')
if stat < 1:
print('All stats should be no less than 1')
elif stat > 4:
print('All stats should be no more than 4')
elif sum(stats)!= 7:
print('The character should start with 7 points')
create_character(1, 4, 2, 1)
Traceback (most recent call last):
File "main.py", line 12
stats = \[strength, intelligence, charisma\]
^
SyntaxError: unexpected character after line continuation character
if not isinstance(name, str):
print('The character name should be a string')
elif not name:
print('The character should have a name')
elif len(name) >10:
print('The character name is too long')
elif ' ' in name:
print('The character name should not contain spaces')
stats = \[strength, intelligence, charisma\]
for stat in stats:
if not isinstance(stat, int):
print('All stats should be integers')
if stat < 1:
print('All stats should be no less than 1')
elif stat > 4:
print('All stats should be no more than 4')
elif sum(stats)!= 7:
print('The character should start with 7 points')
You are missing an important bit from the instructions:
the function should return
Edit: There are no returns in your code.
Also, you need to wrap your function call in print() to see what it returns in the console. This will be important when you test the final string returned when all validation checks pass.
Please also keep this in mind when you post your code. We cannot test unformatted code or code that is sent in a screenshot.
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.
thankyou @dhess replacing my “prints” with “returns” passed all but 1 test. I still can’t pass test 10. My latest code is:
full_dot = ‘●’
empty_dot = ‘○’
def create_character(name, strength, intelligence, charisma):
if not isinstance(name, str):
return'The character name should be a string'
elif not name:
return'The character should have a name'
elif len(name) >10:
return'The character name is too long'
elif ' ' in name:
return'The character name should not contain spaces'
stats = \[strength, intelligence, charisma\]
for stat in stats:
if not isinstance(stat, int):
return'All stats should be integers'
elif stat < 1:
return'All stats should be no less than 1'
elif stat > 4:
return'All stats should be no more than 4'
elif sum(stats)!= 7:
return'The character should start with 7 points'