Question: Write function, smallestCharLargerThan(keyChar, inputString) that takes as input key character, keyChar, and a string of one or more letters (and no other characters) and prints

Write function, smallestCharLargerThan(keyChar, inputString) that takes as input key character, keyChar, and a string of one or more letters (and no other characters) and prints 1) the "smallest" character in the string that is larger than keyChar, where one character is smaller than another if it occurs earlier in the alphabet (thus 'C' is smaller than 'y' and both are larger than 'B') and 2) the index of the final occurrence of that character. When comparing letters in this problem, ignore case. I.e. 'e' and 'E' should be treated as equal. However, the output should use the case of the smallest letter as it appears at the index of its final occurrence in the string. Thus, in the example below "The smallest character is 'y' ..." would be incorrect. If no character in the given string is larger than keyChar, print an appropriate message. Important: the function must contain exactly one loop and you must determine the index of the character within the loop (i.e. you may not use Python's max, min, index, reverse, [::-1], or find, and you may not use any lists). You may, however, use Python's lower() function to help with string case if you wish.

For example, >>> smallestCharLargerThan("x", "yRrcDefxBqubSlyjYelskd") 

should yield something like:

In 'yRrcDefxBqubSlyjYelskd', the smallest character greater than 'x' is 'Y' and occurs at position 16.

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!