i have done everything up to copy and pasting code from google but nothing working i am not able the pass the lab
Your code so far
full_dot = '●'
empty_dot = '○'
def create_character(character_name, strength, intelligence, charisma):
stats = [strength, intelligence, charisma]
# --- Character Name Validations ---
# 1. Must be a string
if not isinstance(character_name, str):
return "The character name should be a string."
# 2. Must not be empty
if character_name == "":
return "The character should have a name."
# 3. Must not be longer than 10 characters
if len(character_name) > 10:
return "The character name is too long."
# 4. Must not contain spaces
if " " in character_name:
return "The character name should not contain spaces."
# --- Stats Validations ---
# 5. All stats must be integers (exclude booleans explicitly)
if not all(isinstance(s, int) and not isinstance(s, bool) for s in stats):
return "All stats should be integers."
# 6. All stats must be >= 1
if any(s < 1 for s in stats):
return "All stats should be no less than 1."
# 7. All stats must be <= 4
if any(s > 4 for s in stats):
return "All stats should be no more than 4."
# 8. Sum of stats must be exactly 7
if sum(stats) != 7:
return "The character should start with 7 points."
# --- Format Output ---
# Calculate dots: (full * value) + (empty * remaining)
str_dots = full_dot * strength + empty_dot * (10 - strength)
int_dots = full_dot * intelligence + empty_dot * (10 - intelligence)
cha_dots = full_dot * charisma + empty_dot * (10 - charisma)
# Return formatted string with \n newlines and NO colons
return f"{character_name}\nSTR {str_dots}\nINT {int_dots}\nCHA {cha_dots}"
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
By “not working” do you mean you changed the messages and it still doesn’t work? If so, 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:
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.)
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:
stats = \[strength, intelligence, charisma\]
\# --- Character Name Validations ---
\# 1. Must be a string
if not isinstance(character_name, str):
return "The character name should be a string."
\# 2. Must not be empty
elif character_name == " ":
return "The character should have a name."
\# 3. Must not be longer than 10 characters
elif len(character_name) > 10:
return "The character name is too long."
\# 4. Must not contain spaces
elif " " in character_name:
return "The character name should not contain spaces."
\# --- Stats Validations ---
\# 5. All stats must be integers (exclude booleans explicitly)
elif not all(isinstance(s, int) and not isinstance(s, bool) for s in stats):
return "All stats should be integers."
\# 6. All stats must be >= 1
elif any(s < 1 for s in stats):
return "All stats should be no less than 1."
\# 7. All stats must be <= 4
elif any(s > 4 for s in stats):
return "All stats should be no more than 4."
\# 8. Sum of stats must be exactly 7
elif sum(stats) != 7:
return "The character should start with 7 points."
\# --- Format Output ---
\# Calculate dots: (full \* value) + (empty \* remaining)
str_dots = full_dot \* strength + empty_dot \* (10 - strength)
int_dots = full_dot \* intelligence + empty_dot \* (10 - intelligence)
cha_dots = full_dot \* charisma + empty_dot \* (10 - charisma)
\# Return formatted string with \\n newlines and NO colons
return f"{character_name}\\nSTR {str_dots}\\nINT {int_dots}\\nCHA {cha_dots}"