Python代写 | COMP 1039 Programming Assignment 2

本次Python代写是实现一个(heroes and villains)的游戏

COMP 1039 Programming
Assignment 2

PART I SPECIFICATION – WRITING A PYTHON MODULE (LIST MANIPULATION FUNCTIONS)
You are required to write a list_function.py module (containing only the functions listed below). This file is
provided for you (on the course website) however, you will need to modify this file by writing code that implements the
functions listed below. Please read the slides on modules available on the course website if you would like
more information on modules.
You are required to implement a Python module containing the following functions:
1. Write a function called length(my_list) that takes a list as a parameter and returns the length of the list.
You must use a loop in your solution. You must not use built-in functions, list methods or string methods in
your solution.
2. Write a function called to_string(my_list, sep=’, ‘) that takes a list and a separator value as
parameters and returns the string representation of the list (separated by the separator value) in the following
form:
item1, item2, item3, item4
The separator value must be a default argument. i.e. sep=’, ‘
You must use a loop in your solution. You must not use built-in functions (other than the range() and
str() functions), slice expressions, list methods or string methods in your solution. You may use the
concatenation (+) operator to build the string. You must return a string from this function.
3. Write a function called find(my_list, value) that takes a list, and a value as parameters. The function
searches for the value in the list and returns the index at which the first occurrence of value is found in the list.
The function returns -1 if the value is not found in the list.
4. Write a function called insert_value(my_list, value, insert_position) that takes a list, a value
and an insert_position as parameters. The function returns a copy of the list with the value inserted into the
list (my_list) at the index specified by insert_position. Check for the insert_position value
exceeding the list (my_list) bounds. If the insert_position is greater than the length of the list, insert
the value at the end of the list. If the insert_position is less than or equal to zero, insert the value at the
start of the list. You must use a loop(s) in your solution. You may make use of the
list_name.append(item) method in order to build the new list. You must not use built-in functions (other
than the range() function), slice expressions, list methods (other than the append() method) or string
methods in your solution.
5. Write a function called remove_value(my_list, remove_position) that takes a list and a
remove_position as parameters. The function returns a copy of the list with the item at the index specified by
remove_position, removed from the list. Check for the remove_position value exceeding the list
(my_list) bounds. If the remove_position is greater than the length of the list, remove the item at the
end of the list. If the remove_position is less than or equal to zero, remove the item stored at the start of
the list. You must use a loop in your solution. You may make use of the list_name.append(item)
method in order to build the new list. You must not use built-in functions (other than the range() function),
slice expressions, list methods (other than the append() method) or string methods in your solution.
6. Write a function called get_slice(my_list, start, stop) that takes a list, a start value and a stop
value as parameters. The function returns a copy of the list between start and stop-1 (inclusive). Check for
the start and stop values exceeding the list bounds. If the stop value exceeds the list bounds, then make the
stop value the length of the list. If the start value exceeds the list bounds, then make the start value zero (0).
Check for the start value being less than the stop value. If the start value is greater than the stop value, return
an empty list. You must use a loop in your solution. You may make use of the list_name.append(item)
method in order to build the new list. You must not use built-in functions (other than the range() function),
slice expressions, list methods or string methods in your solution.

PART II SPECIFICATION – MANAGE CHARACTER INFORMATION
Write a menu driven program called part2_yourEmailId.py 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 two List objects – one that stores the character’s name and one that stores the character’s
health rating). Character information will be stored in a text file that will be read in when the program commences.
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 hero or villain’s health value. This information is seen in Figure 1 below:
After the program has stored the data (using two List objects, one that stores the character’s name and one that
stores the character’s health value), it will enter interactive mode as described in the following section.
Wonder Woman
90
Batman
80
The Joker
80
Superman
100
Catwoman
50
Aquaman
30
Iron Man
50
Hulk
80
Thanos
90
Figure 1: Character information file format (characters.txt).
Your program will maintain two List objects as follows:
character_list = [] # List to store character’s name
health_list = [] # List to store character’s health value


程序代写代做C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB


本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail: [email protected]  微信:itcsdx


如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。

blank

发表评论