I’m doing the Build an RPG Character Python lab and I’m stuck on the tests related to validating that strength/intelligence/charisma are integers. My function looks fine when I run it, but the tests say it’s not handling non-integer stats correctly. I suspect my isinstance check is wrong, but I can’t understand why ?
What I expected:
If any stat is not an integer (example: "4" as a string), it should return:
All stats should be integers*
*What I’m getting:
Some invalid inputs still pass my integer check.
My 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 name == “”:
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”
# Stat validation (I think this is wrong)
if not isinstance((strength) and (intelligence) and (charisma), int):
return “All stats should be integers”
Other checks (simplified here)
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”
Output formatting
return (
f"{name}\n"
f"STR {full_dot*strength}{empty_dot*(10-strength)}\n"
f"INT {full_dot*intelligence}{empty_dot*(10-intelligence)}\n"
f"CHA {full_dot*charisma}{empty_dot*(10-charisma)}"
)
print(create_character(“ren”, “4”, 2, 1))
print(create_character(“ren”, 4, 2, 1))
My question:
Why does isinstance((strength) and (intelligence) and (charisma), int) behave unexpectedly here, and what is the cleanest Pythonic way to validate all 3 stats are integers without writing 3 separate isinstance() checks?


