Build an RPG character - Build an RPG Character

You need to test your function so you can see the output.

This print statement tests the function:

            return "All stats should be less than 1"

            print (create_character("STR", '',2,5))

But it cannot be INSIDE the function, so it should not be indented.

Change it like this:

            return "All stats should be less than 1"

print (create_character("STR", '',2,5))

I am not sure about what to ask. Terminal say indentation error on line 15 and i have now lost the three upper tests that passed. I have tried the print command besides other things and deleted and restarted a number of times.


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"

for stat in stats:

          if not isinstance (stat,int):

             return "All stats should be integers"

          if stat>4:

              return "All stats should be no more than 4"

          if sum(stat) !=7:

              return  "The character should start with 7 points"

I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

How are you testing this?

You need to test your function with input.

What exactly did you try?

Can you try to edit your post or code and fix all of the indentation errors? Please let me know if you have any questions about that.

It’s hard for me to know if your code looks like this or if the errors happened when you copy/pasted it into the forum

I used the validate method different places still no pass. Especially when I validated just below the definition The once that has passed failed. Right now nothing passes.

To test your function, you need to call it, and print the result.

Do you know how to do that?

Regarding indentation:

Any block of code needs to be indented.

code 
code

def function:
    code code # this is a function so
    code code # code in the function body needs
    code code # to be indented.

    if (this is true):
        code # indent the body of if statement

    for this in that:
        code # indent body of a for loop
        code # indent body of a for loop

print(function(arguments)) #call the function and print outside the function
   

Can you try to fix your formatting according to this guide?
It will not work if indentation is not correct.

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  >= 10:

            return "The character name is too long"

        if  ' ' in name:

            return "The character should not contain spaces"

        for stat in stats:

           if not isinstance (stat,int):

            return "All stats should be integers"

           if stat>4:

            return "All stats should be no more than 4"

           if sum(stat) !=7:

            return"The character should star with 7 points"

Only the first 3 tests passed. Indenting the command after print changes the hue??? My deepest apologies. I have been at this for days.

Put your code in backticks so it is readable on the forum. Like this:
```
code
code
code
```

I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Don’t worry about the tests. Don’t run the tests. You need to get your program working first.

You should be testing it yourself as you go. Use this to test:

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

See what your output is.


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”

print(create_character(‘ren,4.2.1’))

if len  >= 10:

return “The character name is too long”

print(create_character(‘ren,4.2.1’))

if  ’ ’ in name:

return “The character should not contain spaces”

print(create_character(‘ren,4.2.1’))

for stat in stats:

if not isinstance (stat,int):

return “All stats should be integers”

print(create_character(‘ren,4.2.1’))

if stat>4:

return “All stats should be no more than 4”

print(create_character(‘ren,4.2.1’))

if sum(stat) !=7:

return"The character should star with 7 points"

print(create_character(‘ren,4.2.1’))

No activity n the terminal . Pass as before.

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”

print(create_character(‘ren,4.2.1’))

if len  >= 10:

return “The character name is too long”

print(create_character(‘ren,4.2.1’))

if  ’ ’ in name:

return “The character should not contain spaces”

print(create_character(‘ren,4.2.1’))

for stat in stats:

if not isinstance (stat,int):

return “All stats should be integers”

print(create_character(‘ren,4.2.1’))

if stat>4:

return “All stats should be no more than 4”

print(create_character(‘ren,4.2.1’))

if sum(stat) !=7:

return"The character should star with 7 points"

print(create_character(‘ren,4.2.1’))

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”

print(create_character(‘ren,4.2.1’))

if len  >= 10:

return “The character name is too long”

print(create_character(‘ren,4.2.1’))

if  ’ ’ in name:

return “The character should not contain spaces”

print(create_character(‘ren,4.2.1’))

for stat in stats:

if not isinstance (stat,int):

return “All stats should be integers”

print(create_character(‘ren,4.2.1’))

if stat>4:

return “All stats should be no more than 4”

print(create_character(‘ren,4.2.1’))

if sum(stat) !=7:

return"The character should star with 7 points"

print(create_character(‘ren,4.2.1’))

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"

            print(create_character('ren,4.2.1'))

        if len  >= 10:

            return "The character name is too long"

            print(create_character('ren,4.2.1'))

        if  ' ' in name:

            return "The character should not contain spaces"

            print(create_character('ren,4.2.1'))

        for stat in stats:

           if not isinstance (stat,int):

            return "All stats should be integers"

            print(create_character('ren,4.2.1'))

           if stat>4:

            return "All stats should be no more than 4"

            print(create_character('ren,4.2.1'))

           if sum(stat) !=7:

            return"The character should star with 7 points"

            print(create_character('ren,4.2.1'))
 Same output as before. nothing in terminal tests don’t pass.

Regrets, I copy /pasted my code repeatedly.

Your print statement is indented. That means it’s in the function.

The function only runs when it’s called.

If the print calls the function from within the function, it will never run.

I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

I get asyntax error at
print(create_character(‘ren,4.2.1’))

```

    if len(name)  >= 10:         error here

```

        return "The character name is too long"

What does the syntax error say?

Try this button it might help you format your code.

Make sure the M is highlighted and it looks like this

1 Like

I am back again where I started only the two tests pass now. I have tried all I know. Do you see any errors. Terminal does not respond with print command.

I have reset 3 times. Thank you for your patience.

if len(name) > 10:

    return "The character name is too long"

here is my code so far:

full_dot = ‘●’

empty_dot = ‘○’

def create_character (name,strength, intelligence, charisma):

def validate_name(name):

if not isinstance (name, str):

    return "The character name should be a string"

if "" in 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"

stats(strength,intelligence,charisma)

if not isinstance (stat,int):

    return "All stats should be integers"

for stat in stats:

    if stat <1:

        return "All stats should be no less than 1"     

for stat in stats:        

    if stat > 4:

        return "All stats should be no more than 4"

if sum(stats) != 7:

        return "The character should start with seven points"

If you want to print the result of your function, the print() line cannot be indented. If it is indented, it is part of the function and will not run.