In this challenge we will use file handling techniques to read through and access the content of different text files.
We have saved three recipes for the following three magic potions using one text file per recipe:
- Invisibility Potion:
A potion that makes you invisible for a short period of time.
- Aging Potion:
A potion which causes the drinker to temporarily become older. The more of the potion is drunk, the larger the aging which occurs.
- Poison Antidote:
A potion which counteracts ordinary poisons, such as creature bites and stings.
The following Python code opens the text file of the invisibility potion (invisibility-potion.txt) in read-only mode. It then uses a for loop to access and print the content of each line, one line at a time.
Your challenge consists of adding a menu to this code to let the user decide which potion to display on screen. Based on their choice, the program will open the relevant text file and display the recipe on screen.
Add an extra text file to store this new potion:
A potion that causes uncontrollable speaking of nonsense.
Add 1 four-leaf clover and 3 dragon scales into a mortar
Add 1 garlic clove and crush the ingredients
Pour the ingredients into a copper cauldron
Add 2 horned slugs inthe cauldron
Add 3 drops of beetroot juice
Boil and simmer the potion for half an hour
Stir once every 10 minutes, clockwise