Starting from:
$30

$24

Exercise 0 Solution

In this rst exercise, we'll practice a few of the fundamental skills that you should have from cscA08 (or your equivalent previous experience). You will need to complete the following functions in a le called ex0.py. These are meant to be fairly simple, but there's a few things to keep in mind:




The automarker is picky. If you spell a function or le name incorrectly, it will be marked as a 0. The automarker does not like print, import or input statements. So please don't use these.




MarkUs is also picky, 4:00:01 is not 4:00, and no late work will be accepted.




Don't wait until 5 minutes before the exercise is due to discover that you can't log into MarkUs, try it at some point earlier in the week.




Your TA (and other students) will be able to help you during practicals, but please have at least made an attempt at each function before showing up.




greeting




I told you we'd start easy. The function greeting should take a string as a parameter that represents a person's name, and returns a greeting in the form Hello <name how are you today? where <name is replaced by the given name. 1




mutate list







The function mutate list takes a list as a parameter, and modi es that list in the following ways:







Any element that is an integer is multipled by 2




Any element that is a boolean is inverted (True becomes False, False becomes True) Any element that is a string has its rst and last characters removed




The 0th element of the list is set to the string Hello, regardless of what it was originally




The input list will have at least 1 element in it, and all strings will have at least 2 characters in them. Note that this function modi es the input list, it doesn't create a new list. The function shouldn't return anything.







merge dicts







The function merge dicts takes two dictionaries as input, both of the format fstr: list of intsg. The function returns a new dictionary with all key:value pairs from both dictionaries. If the dictionaries share a key, the resulting value will be the list from the second dictionary appended to the list from the rst dictionary.







That is to say it should look something like this:




d1 = { a : [1, 2, 3], b : [4], c : [5, 6, 7]}



d2 = { a : [2], b : [8, 9, 0], d : [10, 11, 12]}



merge_dicts(d1, d2)



{ a : [1, 2, 3, 2], b : [4, 8, 9, 0], c : [5, 6, 7], d : [10, 11, 12]}




merge_dicts(d2, d1)




{ a : [2, 1, 2, 3], b : [8, 9, 0, 4], c : [5, 6, 7], d : [10, 11, 12]}







note that the format has to be exact, there should be 1 space before and after the name.



1

More products