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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started