Player inventory

Challenge
No

Compute inventory weight for a player in an RPG. Tell them how much loot they can carry, or whether they are carrying too much.

Here are the things players can carry

  • Mana potions, up to 10. They weigh two pounds each.
  • Health potions, up to 10. They weigh three pounds each.
  • Armor: none, leather (22 lbs), or chain mail (62 lbs).
  • Weapon: dagger (1 lb), sword (11 lbs), or bow (8 lbs).

The maximum inventory weight is 100 lbs, unless they've cast a carrying spell. That adds 30 lbs to the maximum.

The program should input this info. Whole numbers only for potion counts. Show one of the following messages:

  • You are at your maximum inventory weight. You can't carry any loot.
  • You are carrying too much. You cannot run.
  • You can carry up to [number] lbs of loot.

Validate all input. Numeric data should be integers. Alpha data can be upper- or lowercase, and can contain extra spaces.

Use at least two functions, though you can have as many as you like. Use could have separate functions for each input, or combine them. For example, you could have one function to input a valid integer, and call it twice, once for mana and once for health.

Add comments to each function. Use the docstring format we've discussed.

Here's sample I/O.

  • Player Inventory Weight
  • ====== ========= ======
  •  
  • What is the player's inventory?
  • How many mana potions? 0
  • How many health potions? 0
  • Armor type (N for none, L for leather, C for chain mail)? n
  • Weapon type (D for dagger, S for sword, B for bow)? d
  • Has a carry spell been cast (Y/N)? y
  •  
  • -----------------------------
  • Current inventory weight: 1 lbs
  • Maximum weight: 130 lbs
  • You can carry up to 129 lbs of loot.

Some more:

  • Player Inventory Weight
  • ====== ========= ======
  •  
  • What is the player's inventory?
  • How many mana potions? some
  • Sorry, you must enter a whole number.
  • How many mana potions? 88
  • Sorry, please enter a whole number between 0 and 10.
  • How many mana potions? 2.5
  • Sorry, you must enter a whole number.
  • How many mana potions? 3
  • How many health potions? 17
  • Sorry, please enter a whole number between 0 and 10.
  • How many health potions? 8
  • Armor type (N for none, L for leather, C for chain mail)? l
  • Weapon type (D for dagger, S for sword, B for bow)? b
  • Has a carry spell been cast (Y/N)? n
  •  
  • -----------------------------
  • Current inventory weight: 60 lbs
  • Maximum weight: 100 lbs
  • You can carry up to 40 lbs of loot.

Even more:

  • Player Inventory Weight
  • ====== ========= ======
  •  
  • What is the player's inventory?
  • How many mana potions? 8
  • How many health potions? 9
  • Armor type (N for none, L for leather, C for chain mail)? c
  • Weapon type (D for dagger, S for sword, B for bow)? s
  • Has a carry spell been cast (Y/N)? n
  •  
  • -----------------------------
  • Current inventory weight: 116 lbs
  • Maximum weight: 100 lbs
  • You are carrying too much. You cannot run.

The usual coding standards apply. Upload your solution here, not to Moodle.

Where referenced