2023 My smart TV has an onscreen keyboard feature that allows me to use the remote control to | Assignment Collections
Computer Science 2023 PYTHON : Smart TV Blues
2023 My smart TV has an onscreen keyboard feature that allows me to use the remote control to | Assignment Collections
My smart TV has an onscreen keyboard feature that allows me to use the remote control to enter passwords for online services (e.g., Netflix), enter the names of movies to search for, etc. This keyboard resembles the following:
a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 Delete, Enter, etc.
Unfortunately, my remote control is severely broken due to a coffee spill; the up and down buttons don’t work at all, so I can only move between characters on the keyboard using the left and right buttons. Fortunately, there’s a workaround (sort of): moving off the left edge of a row takes you to the row above, and moving off the
right edge of a row takes you to the row below. This is a nuisance. Being an engineer, I want to measure the “annoyance factor” for each password or movie title that I need to enter using this keyboard (and broken remote).
My annoyance factor is the total number of rows that I have to move between in order to enter a particular string.
For example, consider the password “avalon31”:
I begin at ‘a’. The first character doesn’t count towards the annoyance factor, which is currently 0.
Moving to ‘v’ requires me to move three rows down, adding 3 to my annoyance factor.
Moving back to ‘a’ adds another 3 to my annoyance factor, since I have to move three rows back up.
The letter ‘l’ is one row down from ‘a’, so my annoyance factor only increases by 1 this time.
‘o’ is one row down from ‘l’, adding another 1 to my annoyance factor.
‘n’ is one row back up, so my annoyance factor increases by 1.
‘3’ is three rows below ‘n’, adding another 3 to my annoyance factor.
Finally, ‘1’ is one row above ‘3’, adding a final 1 to my annoyance factor.
Thus, my final annoyance factor is 3 + 3 + 1 + 1 + 1 + 3 + 1, or 13.
Complete the annoyanceFactor() function, which takes a single string of lowercase letters and digits representing the string that I want to enter. The function returns the total number of row changes I need to make.
As a general solution strategy, consider the following:
1. Create a list that holds the letters and digits on the keyboard shown above (Hint: Use Python’s list() function on the concatenation of string.ascii_lowercase and string.digits).
2. Identify the first character’s row number. A character’s row number is equal to its list index divided by 7 (using floor division). For example, ‘c’ (index 2) is in row 0 (2 // 7 is 0), and ‘y’ (index 24) is in row 3 (24 // 7 is 3). This value will be our starting row. (Hint: Python lists have an index() method that is extremely useful here)
3. For each remaining character in the string:
(a) Calculate the current character’s row number using the formula from Step 2.
(b) Use Python’s abs() function to calculate the absolute difference between the new character’s row number and our current row number. Add that value to the “annoyance factor” variable.
(c) Set the current row to the new character’s row number.
Examples:
Method Call Expected Output
annoyanceFactor(“avalon31”) 13
annoyanceFactor(“23fish”) 7
annoyanceFactor(“waterbed”) 11
annoyanceFactor(“ncc1701a”) 9
annoyanceFactor(“excelsior”) 10
We give our students 100% satisfaction with their assignments, which is one of the most important reasons students prefer us to other helpers. Our professional group and planners have more than ten years of rich experience. The only reason is that we have successfully helped more than 100000 students with their assignments on our inception days. Our expert group has more than 2200 professionals in different topics, and that is not all; we get more than 300 jobs every day more than 90% of the assignment get the conversion for payment.