Build an RPG Character - Build an RPG Character

Tell us what’s happening:

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 :slight_smile:

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

Challenge Information:

Build an RPG Character - Build an RPG Character

Welcome to the forum @trying1 !

Are you seeing this syntax error in the console? If not, please switch to “night” theme for now until the current console bug is fixed.

EDIT: You don’t need all of the elif statements. If the code hits a return statement, processing will stop there.

1 Like

Thank you I will turn on night theme check out the console.

Thanks for the tip im just getting my head round it all :slight_smile:

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))

What did you do to test or investigate the problem?

The code you just posted is completely different from what you originally posted.

??

1 Like

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

Doesn’t really matter if the code is long or short, it just needs to work.

What problem are you having now?

What did you do to test or investigate the problem?

Do you have a question about something?

1 Like

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"


test by running the function

it means that you are having that message in situations in which you should not have it, other than situations in which you should have it

so consider the condition, test it

the condition is '' in character_name
so test it

character_name = "ren"
print('' in character_name)

change the first line, find when the condition is True and when it is False
and then think of other possible conditions and test them in the same way

Okay thank you so much !! I will be testing this out :smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.