0% found this document useful (0 votes)
53 views1 page

Character Creation Script in Python

The document contains a Python function to create a character with specified attributes: name, strength, intelligence, and charisma. It includes validation checks for the character's name and stats, ensuring they meet specific criteria. The function generates a formatted string representation of the character's stats using filled and empty dots.

Uploaded by

Ofentse
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views1 page

Character Creation Script in Python

The document contains a Python function to create a character with specified attributes: name, strength, intelligence, and charisma. It includes validation checks for the character's name and stats, ensuring they meet specific criteria. The function generates a formatted string representation of the character's stats using filled and empty dots.

Uploaded by

Ofentse
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

** start of main.

py **

full_dot = '●'
empty_dot = '○'
def create_character(name, strength, intelligence, charisma):
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"

stats = [strength, intelligence, charisma]

if not all(type(s) is int for s in stats):


return "All stats should be integers"

if any(s < 1 for s in stats):


return "All stats should be no less than 1"

if any(s > 4 for s in stats):


return "All stats should be no more than 4"

if sum(stats) != 7:
return "The character should start with 7 points"

def generate_dots(value):
return (full_dot * value) + (empty_dot * (10 - value))

line1 = f"{name}"
line2 = f"STR {generate_dots(strength)}"
line3 = f"INT {generate_dots(intelligence)}"
line4 = f"CHA {generate_dots(charisma)}"

return f"{line1}\n{line2}\n{line3}\n{line4}"

** end of [Link] **

You might also like