I have been able to pass all the tests, except for 11 and 12 (both of which involve being able to get the appropriate out to show on the terminal. I have been able to get it to show the proper output, but not the error messages (“name must be a string”, “STR must be an integer”, etc.) unless I make the “print” on line 39 (the second to last line) a “return” and put a “print” in front of the function on line 40 (which defeats the purpose of the function). I suspect I am supposed to expand line 39 with a conditional, but I am not sure what it should be.
Your code so far
full_dot = '●'
empty_dot = '○'
def create_character(name, STR, INT, CHA):
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"
if not isinstance (STR, int):
return "All stats should be integers"
if not isinstance (INT, int):
return "All stats should be integers"
if not isinstance(CHA, int):
return "All stats should be integers"
if STR<1:
return "All stats should be no less than 1"
if INT<1:
return "All stats should be no less than 1"
if CHA<1:
return "All stats should be no less than 1"
if STR>4:
return "All stats should be no more than 4"
if INT>4:
return "All stats should be no more than 4"
if CHA>4:
return "All stats should be no more than 4"
if STR+INT+CHA!=7:
return "The character should start with 7 points"
def STR_visual(STR):
return STR*full_dot+(10-STR)*empty_dot
def INT_visual(INT):
return INT*full_dot+(10-INT)*empty_dot
def CHA_visual(CHA):
return CHA*full_dot+(10-CHA)*empty_dot
character_stats=(f"{name}\nSTR{STR_visual(STR)}\nINT{INT_visual(INT)}\nCHA{CHA_visual(CHA)}")
print(character_stats)
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/144.0.0.0 Safari/537.36 Edg/144.0.0.0
However, if I change one of the variables to be against the rules I coded in, it will only return a blank screen, without returning the intended message.
No. The line of code you offered printed the appropriate output (the name and stats represented by the dots), along with the proper error messages whenever an improper value was placed as an argument.
Noted. Is there something I should do to make it so that there is a return value? I could instead have it be “return character_stats” or should I write a line of code that ensure that the previous return values print .
There are no instructions that ask me to print. In that case, should the print function just be used to help confirm whether the rest of the code is behaving? I have tried to make it so where it is “return charatacter_stats” and then I print the create_character function with the appropriate values. and while that shows up the appropriate output on the terminal it does not satisfy the assignment requirements. Is the second to last line (concerned with the character_stats) where my problem is, or is it something wrong I have been doing through the entire code?
This if the code as it exists right now. I was thinking, might I need to use the elif or else function so that the codes knows to return the character_stats if the other conditionals dont return anything?
full_dot = '●'
empty_dot = '○'
def create_character(name, STR, INT, CHA):
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"
if not isinstance (STR, int):
return "All stats should be integers"
if not isinstance (INT, int):
return "All stats should be integers"
if not isinstance(CHA, int):
return "All stats should be integers"
if STR<1:
return "All stats should be no less than 1"
if INT<1:
return "All stats should be no less than 1"
if CHA<1:
return "All stats should be no less than 1"
if STR>4:
return "All stats should be no more than 4"
if INT>4:
return "All stats should be no more than 4"
if CHA>4:
return "All stats should be no more than 4"
if STR+INT+CHA!=7:
return "The character should start with 7 points"
def STR_visual(STR):
return STR*full_dot+(10-STR)*empty_dot
def INT_visual(INT):
return INT*full_dot+(10-INT)*empty_dot
def CHA_visual(CHA):
return CHA*full_dot+(10-CHA)*empty_dot
character_stats=(f"{name}\nSTR{STR_visual(STR)}\nINT{INT_visual(INT)}\nCHA{CHA_visual(CHA)}")
return character_stats
print(create_character("ren",4,2,1))