CountFire11787
I need to to write Python program that will manage character…

I need to to write Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in when the program commences.  Once the initial character (hero and villain) information has been read in from the file, the program should allow the user to interactively query and manipulate the character (hero and villain) information.  Please ensure that you read sections titled ‘Assignment Specification’ below for further details.

 

 

Please ensure that you read sections titled ‘Assignment Specification’ below for further details.

Write a menu driven program that will allow the user to enter commands and process these commands until the quit command is entered. 

The program will store and maintain character information (using a List of Lists). 

Character information will be AS FOLLOWING:

Wonder Woman

Diana Prince

h 5 5 0 0 90

Batman

Bruce Wayne

h 6 2 0 4 80

The Joker

Jack Napier

v 5 1 0 4 80

Superman

Clark Kent

h 7 4 0 3 100

Catwoman

Selina Kyle

v 12 0 6 6 50

Aquaman

Arthur Curry

h 8 2 2 4 30

Iron Man

Tony Stark

h 10 8 2 0 50

Hulk

Bruce Banner

h 7 2 1 4 80

Thanos

n/a

v 10 2 0 8 90

 

Once the initial character data has been read in from the file, the program should allow the user to interactively query and manipulate the character information. 

 

Input

When your program begins, it will read in character (hero and villain) information from a file called characters.txt.  This is a text file that stores information pertaining to characters (heroes and villains). An example input file called characters.txt can be found on the course website (under the Assessment tab).  You may assume that all data is in the correct format.  The name of the character (hero or villain) is stored on a separate line.  The very next line contains the secret identity of the character (hero or villain).  The very next line contains a character specifying whether the character is a hero (‘h’) or villain (‘v’), followed by the number of battles fought, battles won, battles lost, battles drawn, and a health value.  This information is stored on one line and is separated by the space character as seen in Figure 1 below:

After the program has stored the data (using a List of Lists), it will enter interactive mode as described in the following section. 

Wonder Woman

Diana Prince

h 5 5 0 0 90

Batman

Bruce Wayne

h 6 2 0 4 80

The Joker

Jack Napier

v 5 1 0 4 80

Superman

Clark Kent

h 7 4 0 3 100

Catwoman

Selina Kyle

v 12 0 6 6 50

Aquaman

Arthur Curry

h 8 2 2 4 30

Iron Man

Tony Stark

h 10 8 2 0 50

Hulk

Bruce Banner

h 7 2 1 4 80

Thanos

n/a

v 10 2 0 8 90

Your program will maintain one List of Lists as follows:

 

character_list = []  # List of Lists to store character information

 

 

Once the above information is read in from the file, the character list will be populated as follows:

 

 

character_list

[Wonder Woman, Diana Prince, h, 5, 5, 0, 0, 90]

[Batman, Bruce Wayne, h, 6, 2, 0, 4, 80]

[The Joker, Jack Napier, v, 5, 1, 0, 4, 80]

[Superman, Clark Kent, h, 7, 4, 0, 3, 100]

[Catwoman, Selina Kyle, v, 12, 0, 6, 6, 50]

[Aquaman, Arthur Curry, h, 8, 2, 2, 4, 30]

[Iron Man, Tony Stark, h, 10, 8, 2, 0, 50]

[Hulk, Bruce Banner, h, 7, 2, 1, 4, 80]

[Thanos, n/a, v, 10, 2, 0, 8, 90]

 

 Note: A character and their statistics are stored as a list and are stored as one item in the character list, i.e. a List of Lists (as seen above).

 

 

Interactive Mode

Your program should enter an interactive mode after the character (hero and villain) information has been read from the file.  The program will allow the user to enter commands and process these commands until the quit command is entered.  The following commands should be allowed:

 

1.         list: 

Displays for all characters, the character’s name, number of battles, battles, won, lost, drawn, and their health value.  Outputs the contents of the character list (heroes and villains) as seen below in the section titled Screen Format.  Please read the section at the end of this handout titled – ‘Useful Built-In Python Functions’.

2.         heroes: 

Displays for all heroes, the character’s name, number of battles, battles, won, lost, drawn, and their health value.  Outputs the contents of the character list (heroes and villains) as seen below in the section titled Screen Format.  Please read the section at the end of this handout titled – ‘Useful Built-In Python Functions’.

3.         villains: 

Displays for all villains, the character’s name, number of battles, battles, won, lost, drawn, and their health value.  Outputs the contents of the character list (heroes and villains) as seen below in the section titled Screen Format.  Please read the section at the end of this handout titled – ‘Useful Built-In Python Functions’.

4.         search:

Prompts for and reads the character’s (hero/villain’s) name and searches for the character in the character (hero and villain) list.  If the character is found in the character list, the character’s name, secret identit y, battles fought, won, lost, drawn, and their health value, are displayed to the screen as seen below (in the section titled Screen Format).  If the character is not found in the list of characters (heroes and villains), an error message stating the character has not been found is displayed to the screen.

5.         reset:

Prompts for and reads the character’s (hero/villain’s) name and searches for the character in the character list (heroes and villains).  If the character is found in the list of characters (heroes and villains), the character’s health value is reset to 100.  If the character is not found in the list of characters (heroes and villains), an error message stating the character has not been found is displayed to the screen.

6.         add: 

Prompts for and reads the character’s (hero or villain’s) name, secret identity and whether the character is a hero or villain.  If the character does not already exist (i.e. a match is not found on the character’s name), the character is added to the list of characters (heroes and villains). If the character is added, the health value is initialised to 100 and all other stats (number battles, no won, no lost, no drawn), are initialised to zero and a message is displayed to the screen indicating that this has been successfully added.

The character information must be added after the last character entry stored in the list (i.e. at the end of the list).  If the character is already stored in the character list, an error message is displayed. No duplicate entries are allowed.

7.         remove: 

Prompts for the character’s name.  If the character is found, he/she is removed from the list of characters (heroes and villains) and a message is displayed to the screen indicating that this has been done. If the character is not found in the character list, an error message is displayed.

8.         high:

Displays the character with the highest number of battles won in the list of characters.  Where two characters have the same number of battles won, the character with the lower number of battles fought should be displayed to the screen – see section titled ‘Screen Format’ below.  If no characters are stored in the list or a character with the highest number of battles won cannot be found (i.e. all characters have zero battles won), display an error message accordingly.

9.         battle:

Prompts for the name of the two opponents to do battle.  The program searches for each character in the list of characters (heroes and villains) and if the character is not found in the list of characters, an error message is displayed to the screen and the user is asked to enter another character (hero/villain).

If the opponents are found in the list of characters (heroes and villains), they are then able to do battle and the number of battle rounds the heroes/villains will undertake (a number between 1-5 inclusive) is prompted for and read.  One battle may have many (1-5 inclusive) rounds.  The heroes/villains battle until either an opponent dies (health status is reduced to zero) or the number of battle rounds have been completed.  For each individual battle round, the hero/villain will sustain a certain amount of damage to their health rating.  The amount of damage sustained from the battle will be a randomly generated value between 0-50 inclusive.  After each round, each opponents damage value (i.e. randomly generated number between 0-50 inclusive) and current health value (i.e. calculated by: health value – damage value) are displayed to the screen.

After every battle (however many rounds), a winner is determined (i.e. the opponent with the higher health value wins the battle) and the opponents’ battle statistics are updated (i.e. number of battles, no won, no lost, etc…) accordingly.

10.       health:

Displays the list of characters (heroes and villains) in descending order of health.  Where two characters have the same health status, the character with the highest number of battles fought should appear first. This command should not alter the original list of characters in any way. The information is displayed to the screen as described in the section titled ‘Screen Format’ below.

 

11.       quit:

Causes the program to quit, outputting the contents of the character list (List of lists) to a file (see section ‘Final Output’ below for format).