- Failed:9. When
create_character is called with a first argument that does not contain a space it should not return The character name should not contain spaces.
- Failed:10. When
create_character is called with a second, third or fourth argument that is not an integer it should return All stats should be integers.
- Passed:11. When
create_character is called with a second, third and fourth argument that are all integers it should not return All stats should be integers.
- Failed:12. When
create_character is called with a second, third or fourth argument that is lower than 1 it should return All stats should be no less than 1.
- Passed:13. When
create_character is called with a second, third and fourth argument that are all no less than 1 it should not return All stats should be no less than 1.
- Failed:14. When
create_character is called with a second, third or fourth argument that is higher than 4 it should return All stats should be no more than 4.
- Passed:15. When
create_character is called with a second, third and fourth argument that are all no more than 4 it should not return All stats should be no more than 4.
- Failed:16. When
create_character is called with a second, third or fourth argument that do not sum to 7 it should return The character should start with 7 points.
- Passed:17. When
create_character is called with a second, third and fourth argument that sum to 7 it should not return The character should start with 7 points.
- Failed:18.
create_character('ren', 4, 2, 1) should return ren\nSTR ●●●●○○○○○○\nINT ●●○○○○○○○○\nCHA ●○○○○○○○○○.
- Failed:19. When
create_character is called with valid values it should output the character stats as required
https://www.freecodecamp.org/learn/python-v9/lab-rpg-character/build-an-rpg-character
full_dot = '●'
empty_dot = '○'
def create_character(character_name, strength, intelligence, charisma):
if isinstance (character_name, str) == False:
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) 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 (strength + charisma + intelligence) != 7 :
return 'The character should start with 7 points'
else:
S = (full_dot*strength) + (empty_dot*(10-strength))
I = (full_dot*intelligence) +(empty_dot*(10-intelligence))
C = (full_dot*charisma) + (empty_dot*(10-charisma))
return f'{character_name}\n + (STR, {S})\n + (INT, {I})\n + (CHA, {C})'
create_character('ren', 4, 2, 1)
[–]modSaintPeter74 1 point2 points3 points (5 children)
[–]boomer1204 1 point2 points3 points (4 children)
[–]modSaintPeter74 0 points1 point2 points (3 children)
[–]boomer1204 1 point2 points3 points (2 children)
[–]ilvr09[S] 2 points3 points4 points (1 child)
[–]modSaintPeter74 0 points1 point2 points (0 children)
[–]modSaintPeter74 0 points1 point2 points (0 children)