Question: A hash function is a function that maps data of any size to data of fixed size and has numerous applications; an important one is

A hash function is a function that maps data of any size to data of fixed size and has numerous applications; an important one is verifying if a file you download is truly the file you thought you were downloading. You can hash strings, for example, by assigning each letter a value, adding up the values of the letters, and then taking the remainder of the sum divided by your fixed size. You will be creating this simple hash function that returns a hash value for the given string. Create a function named hash_func that accepts one string as an input argument and sums up the values of the letters in the string according to the conditions given below. Afterward, return the remainder of that sum divided by 10. (You can assume the string has digits and the letters a-z in lowercase).

Values: all the digits in the string will retain the same value all the vowels in the string (a,e,i,o,u) = 3 all other letters = 1

Example with Explanation: hash_func('ironman3') returns 6 Here, sum_of_letters = i+r+o+n+m+a+n+3 = 3+1+3+1+1+3+1+3 value = remainder when the sum_of_letters is divided by 10 = 6

Similarly: hash_func('2fast2furious') returns 5 hash_func('se7en') returns 5 hash_func('123456') returns 1 Hint: You will need a loop and selection statements to do this!

This exercise combines string traversal with branching similar with what we did in the FizzBuzz lab, without the file IO. For example: Test Result print(hash_func("ironman3")) 6 print(hash_func("2fast2furious")) 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!