Part 3 mini-project: Character Sheet

This project pulls together all of Part 3: variables, strings, numbers, and keyboard input.

It asks the user a few questions about their game character, then prints a formatted character sheet with every answer plus one value the program works out itself.

What to build

A program that, when run:

  1. Prompts the user for five pieces of information about a character:

    • Name (text)
    • Class (text, e.g. "Warrior", "Mage", "Rogue")
    • Level (whole number)
    • HP (whole number — hit points)
    • MP (whole number — magic points)
  2. Computes a value called Power, using this formula:

     power = hp + mp * 2 + level * 10
  3. Prints a character sheet in roughly this shape:

     +--------------------------------------+
     | CHARACTER SHEET                      |
     +--------------------------------------+
     | Name : Keiko
     | Class: Mage
     | Level: 7
     | HP   : 95
     | MP   : 60
     | Power: 285
     +--------------------------------------+

The box widths do not have to match exactly. What matters is that every value appears with a label, and the Power line shows the computed value.

Files

The starter and finished versions are in projects/02-character-sheet/:

  • starter.py — the prompts laid out with TODO comments. Finish it so the sheet prints at the end.
  • finished.py — a working version. Look at it after trying yours.

Run with:

python projects/02-character-sheet/starter.py

Hints

  • Each prompt uses input("Label: "). Wrap any value you will do maths on with int(), e.g. int(input("HP: ")).
  • Use an f-string like f"| Name : {name}" for the labelled lines — cleaner than joining strings with +.
  • For the borders, "-" * 38 or similar saves you typing dashes by hand.

What you cannot use yet

  • if to validate input. If the user types "abc" for HP, the program errors. That is fine for now.
  • Loops. Write every prompt out explicitly.
  • Your own functions. Built-ins (input, print, int, str) are all fair game.

Done?

If the sheet shows every value with a label and the Power line is the correct sum, you are done. Move on to Chapter 16 — if / elif / else, where input validation becomes possible.