Creating a player character.

Role playing games require players to adopt a virtual character in the game. Characters often have traits recorded as numerical values for strength, dexterity, constitution, intelligence, wisdom and charisma. This program creates a simple character and saves it to a file.


Write a program that asks the user to enter the name of a character, together with their health, attack and defend as numbers. The program should write the data to a file.

Use this boilerplate code as a starting point:

Success Criteria

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

Complete the subprogram called `make_character` that:

  1. Asks the user to input the name of the character.
  2. Asks the user to input stats for: health, attack and defend values.
  3. Stats must be validated as numbers to be accepted.
  4. Returns a list with the name and stats.

Complete the subprogram called `save_character` that:

  1. Takes a list of attributes as a parameter.
  2. Opens a file for writing data. The name of the file is the name of the character + “.txt”
  3. Writes “[Name]” to the file followed by the character name on a new line, followed by a blank line.
  4. Writes “[Attributes]” to the file followed by each attribute on a new line.
  5. Closes the file.

Complete the `main program` so that:

  1. The `make_character` and `save_character` subprograms are called.
  2. Outputs “Character saved.”

Typical inputs and outputs from the program would be:

Enter the name of the character: Elf

Enter health: 10

Enter attack: 13

Enter defend: 8

Character saved.

Knowledge Organiser

Use these resources as a reference to help you meet the success criteria.

Programming guide:


Run the unit tests below to check that your program has met the success criteria.







Check that you have:

  • Used comments within the code to describe the purpose of subprograms, conditions and iterations.
  • Used meaningful identifier names. That means the names of subprograms and variables indicate what they are for.
Craig'n'Dave logo

Craig ‘n’ Dave

In partnership with

Mission Encodeable
Bett Awards 2024 Finalist