Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In python (um it\'s a question on the practice exam so it definitely does not re

ID: 3703486 • Letter: I

Question

In python (um it's a question on the practice exam so it definitely does not require 2 hours to solve one question)

Imagine you are part of a team that's developing a system to correct mis-typed words Someone else on your team has implemented a function qwerty letter distance (charl, char2) that takes two lower-case letters and returns the qwerty-letter-distance between them. Here, the qwerty-letter-distance between two characters is a measure of how far apart they are on a standard US keyboard For example, qwerty_letter_distance('e'>qwerty_letter_distance ('e','r) in other words the qwerty-letter-distance between 'e' and 'b' is greater than the qwerty-letter-distance between e' and 'r' (because 'b' is further from 'e' on the keyboard than 'r' is) 1 2 3 4 56 7 8 9 0 Tab Caps Lock | A |S |D |F |G |H |J |K |L |- |Enter 4 4 Menu C Key Kay In this problem you will write and use a function to compute the qwerty-word-distance between two words of the same length, word1 and word2, as the sum of the qwerty-letter-distances between the corresponding letters in word1 and word2 (letters in the same position) For example, if the qwerty-letter-distance between b' and 'c' is 2, between 'a' and 'a' is 0, and between 'y' and t' is 1, then the qwerty-word-distance between "bay" and "cat" is 3, since 2+0+13 Your task is to implement the following 2 functions: qwerty_word_distance (wordl, word2) that gets two strings of the same length, wordl and word2. Each word contains only lowercase letters The function computes and returns the qwerty-word-distance between wordl and word2 For example, under the assumptions above, qwerty_word_distance ("bay", "cat") should return 3 Note: You do NOT need to know any of the details of how qwerty-letter-distance is defined or computed- someone else has implemented that function and you can call it. find_close_words (word_list, test_word, num) that gets a list of words, word list, an additional word, test word, and a positive integer num The function creates and returns a sub-list of the words from wor * t such that

Explanation / Answer

def qwerty_word_distance(word1,word2):

a = 0

for i in range( len(word1)):

a = a + abs(ord(word1[i] - ord(word2[i]))

return a

def find_close_words(word_list , test_word , num):

for i in range( len( word_list)):

a = qwerty_word_distance(word_list[i] , test_word)

if a > num :

del word_list[i]

return word_list