Build an RPG Character - Build an RPG Character

Tell us what’s happening:

I could use some support, can’t get past set #7 as I have no idea how to do what it’s asking. When I check others work I see everyone is using language that hasn’t been taught yet!

Your code so far

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'

print(create_character('',1,2,3))


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36

Challenge Information:

Build an RPG Character - Build an RPG Character

What is #7? Can you be more specific about what part of that sentence is confusing you?

Do you mean test 7? Try to implement the User Stories first. Don’t worry about the tests until you are done that.

Can you think of a way to check if a variable is an integer?

Can you think of a way to check if a variable is a string?

Test #7

This isn’t a solution though, it’s asking to check all three variables at once

Yes, we aren’t going to write a solution for you. That’s against the rules.

Do you know how to do this? It feels relevant

yes, I’m fully aware of how to check, it’s literally in my code above. I’m not asking for the solution, I’m asking how I’m supposed to complete the project using only the code taught up to this point.

Where is your code checking if something is an integer? I’m not seeing it.

Just worry about checking if one variable is an integer. We can build from there to checking if any one of three variables in an integer.

my bad I thought I included it, so I’d need to store the answer for each integer check like below? Just seems excessive

Please post the actual code instead of a picture, and I cannot run the code in your picture.

That works, but ideally we should be able to handle this in one elif. What did the earlier lessons say was a way to check if one of two logical conditions was true?

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'
    if isinstance(strength, int) or isinstance(intelligence, int) or isinstance(charisma, int) == Flase:
        return 'almost there'
    else:
        return 'Good to go'

    #if not isinstance(strength, int): 
     #   if intelligence and charisma == int:
      #      return 'This shit worked'
    #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'
    
print(create_character('zac',4,3,4))

Two problems

  1. how do you spell ‘flase’?

  2. The or operator separates logically independent statements. So (full statement 1) or (full statement 2). That doesn’t appear to be what you’re attempting though. (You can always use ( ) around each part of the or to clearly logically group the independent statements).

Gotcha, so I would need to wrap the second set like below:

def testing_for_int (strength, intelligence, charisma):
    if isinstance(strength, int) != (isinstance(intelligence, int) and isinstance(charisma, int)):
        return 'not good'
    else:
        return 'good'
print(testing_for_int(2,1,3))

Hmm, let’s look back at the version with 3 separate elif that worked. Those are logically independent checks. Your latest code doesn’t look like that.

Specifically, everything before the or isn’t a single independent logical condition that matches what you want.

It seems to work:

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'
    if isinstance(strength, int) != (isinstance(intelligence, int) and isinstance(charisma, int)):
        return 'All stats should be integers'
    else:
        return 'ints check out'
    
print(create_character('Zac',2,3,4))

Unfortunately only accidentally. What happens if the third stat isn’t an int but the first two are?

This is really frustrating

Yeah, coding is like that.

Like I said, you need three independent checks. You have those above in separate elifs. Each of those checks is right. They can be linked with ors as long as the checks stay separate. You use ( ) to keep the checks separate.

Think about the logical statements you’re making in English.

What you want is this:
IF strength is an int AND intelligence is an int AND charisma is an int, THEN they are all int and we are good. OTHERWISE return an error.

In your first attempt, you used not which is also fine. Just know you are checking the opposite:
IF strength is NOT and int OR intelligence is NOT an int THEN return an error.