Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS1010E: Programming Methodology

Assignment 4: Map, Filter, Search, Sort, OOP

Instructions

Submission Instructions

Failure to follow any of the instructions above will result in a deduction of your marks.

Files

Assignment04.pdf

A4_q1_template.py

A4_q2_template.py

A4_q3_template.py

A4_q4_template.py

A4_q5_template.py

A4_q6_template.py

Coursemology

Assignment  4:  Map, Filter, Search, Sort, OOP

** Attention: This assignment contains 6 Questions, where

Question 4 and Question 6 convey 1 CA mark each.

**********

Question 1: Hash Keys (S&S)

Develop a program to get any input string and return a tuple of 2 hash keys computed for that string.

(hk1 , hk2) = hash_keys(instr)

 def hash_ keys( instr ): pass return (hk1,hk2,)

The first hash key would be computed by XORING all the characters of the input string instr. You need to find a way to get the code (ASCII or UNICODE) of each character.

The second hash key would be computed by multiplying characters of instr by          consecutive powers of 2, adding the results together, and computing the remainder of its division by 1024.

 Example: instr = ‘abcd’ hk1 = a xor b xor c xor d hk2 = (a*2**0 + b*2**1 + c*2**2 + d*2**3) % 1024

Points:

You need to find: a way to access the characters of a string, a function that

returns the ASCII/Unicode code of a character, and the XOR operator.

•        Check the test cases 1 to 3, (‘a’, ‘aA’, ‘Aa’). Why the hash keys are like that?

Add your answer as a comment at the end of your code before submitting.

Test Cases:

 >>> hash_keys( 'a' ) (97, 97) >>> hash_keys( 'aA' ) (32, 227) >>> hash_keys( 'Aa' ) (32, 259) # Why? What do you think? Add your