๐Ÿ“ข Too many exams? Donโ€™t know which one suits you best? Book Your Free Expert ๐Ÿ‘‰ call Now!


    Question

    Complete a simple hash function for a string s that sums

    the ASCII values of its characters and then takes the modulo of a prime number M. def simple_hash(s, M): ย  ย  hash_val = 0 ย  ย  for char in s: ย  ย  ย  ย  _________ # Line to complete (add ASCII value) ย  ย  _________ # Line to complete (modulo operation) ย  ย  return hash_val
    A hash_val += ord(char) ; hash_val = hash_val % M Correct Answer Incorrect Answer
    B hash_val += char ; hash_val %= M Correct Answer Incorrect Answer
    C hash_val = ord(char) ; hash_val = hash_val % M Correct Answer Incorrect Answer
    D hash_val += ord(char) * M ; hash_val = hash_val % M Correct Answer Incorrect Answer
    E hash_val += ord(char) ; return hash_val % M Correct Answer Incorrect Answer

    Solution

    The correct answer is A

    Practice Next
    More IT Operating System Questions
    ask-question