I am extremely lost on how to proceed with the code.
Even if i create new names for stats, how should I implement whatever the system is asking of me?
Also, half of tests were not passed due to wrong coding, I assume, but I fail to see the mistakes
Your code so far
full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intel, charisma):
if not isinstance (name, str):
return "The character name should be a string."
if len(name) == 0:
return "The character should have a name."
if len(name) >10:
return "The character name is too long."
if "" in name:
return "The character name should not contain spaces."
if not isinstance (name, strength, intel, charisma, (int)):
return "All stats should be integers."
if strength <1 or intel <1 or charisma <1:
return "All stats should be no less than 1."
if strength>4 or intel>4 or charisma >4:
return "All stats should be no more than 4."
if strength + intel + charisma <7 or name + strength + intel + charisma >7:
return "The character should start with 7 points"
return 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/149.0.0.0 Safari/537.36
Check the punctuation in your validation messages. They should match exactly to the instructions.
That looks like an empty string, not a space.
The syntax for isinstance is not correct. You can check a single a variable against multiple types, but you cannot check multiple variables against a single type. And should name be an int?
Why are you attempting to sum name, a string, and the stat parameters of type int?
And you still need to complete this function by returning the final string described in User Story #5.
I have fixed the factors you suggested. I’m stuck on n3, n5, n7, n9 and so on. Whatever prompt says “if x does not contain, it should not return STRING”, marked as incomplete. How can I code it without putting else: pass at the end of every single if function?
For example:
full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intel, charisma):
if not isinstance(name, str):
return 'The character name should be a string'
if len(name) == 0:
return 'The character should have a name'
if len(name) >10:
return 'The character name is too long'
if " " in name:
return 'The character name should not contain spaces'
if not isinstance(strength, int) or not isinstance(intel, int) or not isinstance(charisma, int):
return "All stats should be integers."
if strength <1 or intel <1 or charisma <1:
return "All stats should be no less than 1."
if strength>4 or intel>4 or charisma >4:
return "All stats should be no more than 4."
if strength + intel + charisma !=7:
return "The character should start with 7 points"
else:
pass
return create_character('ren', 4, 2, 1)
n3 gives me “When create_character is called with a first argument that is a string it should not return The character name should be a string.”
You are trying to return a function call. A function call should be done outside of the function and should be wrapped in a print() to see what your function is returning.
Your function should return the string described in User Story #5.
Also, not all of your return messages match exactly to the instructions.
You should never need to use pass to complete this challenge.
The User Story #5 was what I was mostly stuck on but a quick google search has helped me to understand what exactly was required of me.
Thank you for you help, I’m still wobbly on print and return functions even though logically I understand the difference, and of course punctuation is a pain in the **s.