Heya, so I am doing the RPG and I’ve seen loads of people with similar issues (I guess). Some people are using a dictionary but I tried that and to hard code and I just can’t seem to even pass the first test ??
If you have any tips for me to be put towards the right direction I would much appreciate it. I do not want the answer, im here to learn
Your code so far
full_dot = '●'
empty_dot = '○'
def create_character(charactername, 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'
if not isinstance(strength, int):
return 'All stats should be integers'
elif not isinstance(intelligence, int):
return 'All stats should be integers'
elif not isinstance(charisma, int):
return 'All stats should be integers'
elif strength < 1:
return 'All stats should be no less than 1'
elif intelligence < 1:
return 'All stats should be no less than 1'
elif charisma < 1:
return 'All stats should be no less than 1'
elif strength > 4:
return 'All status should be no more than 4'
elif intelligence > 4:
return 'All status should be no more than 4'
elif charisma > 4:
return 'All status should be no more than 4'
sum_stats = strength + intelligence + charisma
elif sum_stats != 7:
return 'The character should start with 7 points'
else:
str_full_points = full_dot * strength
str_empty_points = (10 - strength) * empty_dot
str_points = str_full_points + str_empty_points
int_full_points = full_dot * intelligence
int_empty_points = (10 - intelligence) * empty_dot
int_points = int_full_points + str_empty_points
cha_full_points = full_dot * charisma
cha_empty_points = (10 - charisma) * empty_dot
cha_points = str_full_points + str_empty_points
return (
name
"STR", " ", str_points,
"INT", " ", int_points,
"CHA", " ", cha_points
)
# example code
print(create_character('ren', 4, 2, 1))
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.2 Safari/605.1.15
I fixed up the code using or’s like I tried before, I’ve managed to get the ticks up to 6 but nothing for numbers. I just want to check im not missing anything ?
Hereis my code:
full_dot = '●'
empty_dot = '○'
def create_character(character_name, strength, intelligence, charisma):
if isinstance(character_name, str) !=True:
return 'The character name should be a string'
if character_name == '':
return 'The character should have a name'
if len(character_name) > 10:
return 'The character name is too long'
if '' in character_name:
return 'The character name should not contain spaces'
if not (isinstance(strength, int) and isinstance(intelligence, int) and isinstance(charisma, int)):
return "All stats should be integers"
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 not (strength + intelligence + charisma) == 7:
return "The character should start with 7 points"
str_full_points = full_dot * strength
str_empty_points = (10 - strength) * empty_dot
str_points = str_full_points + str_empty_points
int_full_points = full_dot * intelligence
int_empty_points = (10 - intelligence) * empty_dot
int_points = int_full_points + str_empty_points
cha_full_points = full_dot * charisma
cha_empty_points = (10 - charisma) * empty_dot
cha_points = str_full_points + str_empty_points
return (character_name,"\n" "STR", " ", strength, "\n", "INT", " ", intelligence, "\n", "CHA", " ", charisma )
# example code
print(create_character('ren', 4, 2, 1))
yes I realised how long the elif where so I decided to cut it down to using or statements. I pretty much scrapped the whole second half of code and redid it
Okay so I did a little bit of thinking and I don’t want it to get confused and I think I was using and, instead of or in one.
So, this is what I have done. In the console there is no error message but when I put
print(create_character(‘ren’, 4, 2, 1) it says there should be no spaces yet I’ve passed task 6.
I am just confused in general and want to know if im am in the right direction, it isn’t passing the code below (Which is inside the enclosed function) so im not sure if I just can’t do it.
if you can help me know which direction I should look into because I can’t see theflaw
sum_characters = strength + intelligence + charisma
if not isinstance(strength, int) or not isinstance(intelligence, int) or not isinstance(charisma, int):
return "All stats should be integers"
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 sum_characters != 7:
return "The character should start with 7 points"