def do_action(decision, game_data, current_location,
inventory):
'''
(int, dict, float, list) -> str
Given the game data dict, and the current location ID, get
all the possible actions at that location.
If the decision number given as 'decision' falls outside the
number
of allowed actions at this location, then return the string
"Invalid decision. Please select choice from the decisions
listed."
Make sure this string is EXACTLY as above.
Else, if the decision is valid, then figure out the location
information
of the new location ID that the player should end up at after
doing this decision (use game_data, current_location, and the
decision
chosen to figure this out).
Check for any items at this new location and add to inventory
(remember you
can call already existing functions to make your code shorter
and less repetitive).
Return the text description of the new location ID where you end
up
after doing this action (e.g. the same way that visit_location
function
returns text description of visited location).
'''
# YOUR CODE HERE #
pass
#python
As per your given data and with some assumptions i have created the function. You just have to edit some of it according of the rest of the functions that you have. Here is the code:
valid_nums = list() # List of valid decisions
def do_action(decision, game_data, current_location, inventory):
inventory = list() # Inventory with items
game_data = dict() # Dictionary with game data
new_location = None # New_location
if decision not in valid_nums:
return "Invalid decision. Please select choice from the decisions listed."
else:
# Assuming you habe game_data have keys as decision number and values as locations
for i in game_data.keys():
if decision == i:
new_location = game_data[i]
# Assuming you have a function already for the inventory search
if find_item(new_location) != None:
inventory.append(find_item(new_location))
return visit_location(new_location)
Thank you.
def do_action(decision, game_data, current_location, inventory): ''' (int, dict, float, list) -> str Given the game data...
def check_items(current_location, game_items, inventory): ''' (float, dict, list) -> None Given a float location id and a dict of game items, check if any of the game items are found in the current location provided. If they are, add them to the inventory that's provided. The game_items dict has item names as keys, and values as lists with the following information in this order: [description of item, location ID of where the item is found, location ID of where...
def get_average_club_count(person_to_clubs: Dict[str, List[str]]) -> float: """Return the average number of clubs that a person in person_to_clubs belongs to. >>> get_average_club_count(P2C) 1.6 >>> get_average_club_count({'Bob': ['X', 'Y'], 'John': []}) 1.0 """ This is the function I need to test for edge cases, I need to have a test case such that it will detect that the input has been modified(mutation). What test case would I implement?
Python Code help needed. Based on the file (2nd picture) a dictionary like the third picture is to be made. def load_locations(filename): (str) -> dict Read data from the file with the given fi lename and create and return a dictionary with location data, structured as descr ibed in the ass ignment handout, Part 1 Section I1 [BEGIN DESCRIPTION There is nothing interesting here [END DESCRIPTION] BEGIN DESCRIPTION] You wake up lost in some unfamiliar place. All you know is...
Python help it is a grade 12 course def find astrological sign(month, date): (int, int)-str Given two int values represent ing a month and a date, return a 3-character string that gives us what star sign a person born in that month and on that date belongs to, Use the SIGNS string (already defined for you at the top of this file) to figure this out. NOTE FROM BOB: A lot of string slicing to do here. It looks like...
SIGN_GROUPS = '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN]' def get_sign_group(sign): ''' (str) -> int Given a three character string representing a star sign, return which group (out of 0, 1, 2, or 3) this star sign belongs to. Use the SIGN_GROUPS string (already defined for you above) to figure out the group. i.e. As given by this string '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN]' the signs ARI, LEO and SAG are in group 0, the signs TAU, VIR, CAP are in group 1, and so on. >>> get_sign_group('ARI') 0 >>>...
SIGN_GROUPS = '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN]' def get_sign_group(sign): ''' (str) -> int Given a three character string representing a star sign, return which group (out of 0, 1, 2, or 3) this star sign belongs to. Use the SIGN_GROUPS string (already defined for you above) to figure out the group. i.e. As given by this string '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN]' the signs ARI, LEO and SAG are in group 0, the signs TAU, VIR, CAP are in group 1, and so on. >>> get_sign_group('ARI') 0 >>>...
python: def functionSolver(function: callable)->str You will be given a function as a parameter, the function you are given only accepts two number parameters and produces a float value. It is your job to figure out what mathematical operation the function you are given is performing by passing it many different parameters. The possible operations the function can perform are: add, subtract, multiply, and divide. The given function will only perform a single operation, it will not change after consecutive invocations....
Hey guys I need help with this assignment. However it contains 7 sub-problems to solve but I figured only 4 of them can be solved in one post so I posted the other on another question so please check them out as well :) Here is the questions in this assignment: Note: Two helper functions Some of the testing codes for the functions in this assignment makes use of the print_dict in_key_order (a dict) function which prints dictionary keyvalue pairs...
This CSIS 9 Python. Java Python Warmup-2 > string_times prev next | chance Given a string and a non-negative int n, return a larger string that is n copies of the original string. string_times('Hi', 2) – 'HiHi' string_times('Hi', 3) - 'HiHiHi' string_times('Hi', 1) – 'Hi' Solution: Go Save, Compile, Run (ctrl-enter) Show Solution def string_times (str, n): def string_times(str, n): result = "" for i in range(n): # range(n) is [0, 1, 2, .... n-1] result = result + str...
List at least 6 suggestions for improving this class. Highlight the code using a box and the draw an arrow from that box to write your comments in the right column (example shown). 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 25 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47...