Starting from:

$34.99

IT5001 Assignment 4 - Sequences Solution


Submission instructions:
1. You cannot use other functions from other packages that are not given in the skeleton file
2. You must name your functions exactly as the questions stated.
3. The functions to be submitted should work for both tuples and lists. And you should NOT change the value of the input.
4. No mark will be given if the code cannot be compiled and run in coursemology.
Write a function, describe_data, that takes a sequence L and prints each element within it along with its type.
Sample output:

Write a function, howManyInt(), that takes in a sequence L. The function return how many integers are there in the list. Note that the number “10.0” is NOT an integer. Also, you do not need to go into a nested sequence.
NOTE: No credit will be given if the inbuilt function “count” is used.


You are given a wave as a list. Your job is to smooth the wave out by a simple filtering technique. You are given a wave in a list named ‘original_wave’ as follows:



Write a function ‘filter_wave(wave,1)’ and this will produce a new wave which is a smoothed version of the input ‘wave’. Following the rules below
• In the new wave, for every position i, it is the weighted sum of three positions of the original wave. More preciously, the new wave value in position i will be equal to
new_wave[i] = wave[i-1] * 0.2 + wave[i]*0.6 + wave[i+1]*0.2
• Let len(wave) be L. The above method will access wave[-1] and wave[L] in which do NOT exist in the original wave. So, you can deem the values of wave[-1] and wave[L] as 0.
• You should NOT modify the original wave input
• And all the number in the new wave will be integers. You can simple use the function int() to convert any number into an integer.
Here is the expected shape of the wave after filter_wave(original_wave_sample,1)

Finally, modify the function ‘filter_wave(wave,n)’ for n ≥ 0. And this will repeat the filtering n times to the wave accumulatively and produce an even smoother wave. Here is the expected wave for filter_wave(original_wave_sample,10)


We are going to fly a lot of drones to scout out an area!

Everything is ready except that they need some resistors in their main circuits! For each drone, it needs two extra resistors that must be connected in series to produce the desired total resistance. Namely, total resistance R = R1 + R2.

For example, if you need a total resistance of 10 ohms, you can connect two resistors with resistances 2 ohms and 8 ohms, or another pair of 3 ohms and 7 ohms. You are given as many drones as possible, and they all need the same resistance R. In your hands, you are given a lot of resistors such that every resistor is unique and none of them has the same resistance with each other (Note that we will relax this uniqueness requirement in the later part). And of course, every resistor has a positive non-zero integer value of resistance. Your task is, given a tuple that contains the resistance values of all the resistors, find out all the pairs of resistors that can produce a total sum of R ohms. For example, if you have a tuple of resistors:

You can call your function to find out what are the combinations for different total resistance. These two examples find all the resistors that can sum up to 150 ohms and 152 ohms.

Write the function ‘matchResistors(R,n)’ to return a list of tuples L. And each of the tuple contains a pair of resistor in the list L that sum up to R like the examples above.
• You cannot modify the original input. And your function should work with inputs of both lists and tuples. You cannot hardcode the input
• Every item in your output must be unique (in this part). Namely, you cannot output the same pair twice, even if you swap the two values.
The followings are two more tasks. We recommend you to make a backup for the above and just submit it in case you cannot finish the following two parts.

1000000. (The function shuffle() is just used to create an example input list. Namely, it just randomly shuffle the list.)

More products