Build an RPG Character - Build an RPG Character

Tell us what’s happening:

I cannot seem to get stats to work and I cannot for the life of me understand I have checked the web, my notes and I just don’t seem to see what I did wrong.

Your code so far

full_dot = '●'
empty_dot = '○'

def validate_name(name):
    if not isinstance(name, str):
      return "The character name should be a string"
    if len(name) > 10 :
      return 'The character name is too long'
    if " " in name:
      return 'The character name should not contain spaces'
    if '' in name:
      return 'The character should have a name'


def validate_stats(strength, intelligence, charisma):
  for stat in (strength, intelligence, charisma):
    if not isinstance(stat, int):
            return 'All stats should be integers'

  for stat in (strength, intelligence, charisma):
    if stat < 1:
      return 'All stats should be no less than 1'

  for stat in (strength, intelligence, charisma):
    if stat > 4:
      return 'All stats should be no more than 4'

    if strength + intelligence + charisma != 7:
      return 'The character should start with 7 points'

def create_dots(stat):
    return stat * full_dot + empty_dot * (10 - stat)
       

def create_character(name, strength, intelligence, charisma):
    name_error = validate_name(name)
    if name_error:
        return name_error
    stats_error = validate_stats(strength, intelligence, charisma)
    if stats_error:
        return stats_error


    return (
       f'{name}\n'
       f'STR {create_dots(strength)}\n'
       f'INT {create_dots(intelligence)}\n'
       f'CHA {create_dots(charisma)}'
    )
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/142.0.0.0 Safari/537.36 OPR/126.0.0.0

Challenge Information:

Build an RPG Character - Build an RPG Character

Welcome to the forum @harkentoffin

Add this line code of code at the end of the editor.

print(create_character('ren', 4, 2, 1))

Happy coding

I’m still having trouble passing steps 7-12 which I think is basically saying that my validate stats function isn’t working. I’ve been fiddling with it and I don’t really see what I did wrong.

are you using print to test what your function is returning?

I did the edit he said. Currently it’s only printing character should have a name.

then test this, try many different print('' in <string>) to see for which strings you get True and for which you get False

Giving it a shot now but I’m a little confused as to what it’s doing. Is this checking for spaces?

this is the condition you used in your code here:

what is it doing?

I love you. Alright that helped a ton. Now just have to fix it to actually print ‘The character should have a name’. lol
This helped a ton I felt so stupid.

I also don’t understand why my “all stats should be less than 4” isn’t working. It looks sound to me.

The fix I see is to make it look for an empty space and when I do that it cycles back to the same problem.

Just focus on one test at a time

What’s the requirement of the first test that fails?

Are there any errors or messages in the console?
Check the related User Story and ensure it’s followed precisely.
What line of code implements this?
What is the result of the code and does it match the requirement? (what happens when you test you program with input?)

which one are you looking at?

you were investigating this, weren’t you? or you went back to the one above? why?

3, 7, 9 are the only ones I have left.
it’s when it’s an empty string it’s supposed to return ‘The character should have a name’ I have checked spelling and tried a few different edits. It’s why I used an empty string the first time but that throws far more errors. I’m not really sure how I work around it.

what is the requirement?

  • If the character name is an empty string, the function should return The character should have a name.

How do you check this?

If the character name is an empty string

if " " in name:
return ‘The character should have a name’

I thought it would be like this

""  #empty string
" " #space character

But what should do to detect no name if I cannot use an empty string. Or if that is the way then why does that suddenly break the rest of my code. I don’t see the connection if that’s what it is. I’m sorry if I’m a little thick. xD

You need to do some tests. Smaller tests outside the program.

Does the logic you’re using here work? Is that what you want to check for?

this is an example of a first test to see if your idea works, try it, do you get once True and once False? yes? good, no? you need to check in an other way

name_empty_string = ""
name_correct = "brigitte"

print("" in name_empty_string)
print("" in name_correct)