Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions

Question

3. How would you address the problems that make up the situation?

Answered: 1 week ago

Question

2. What recommendations will you make to the city council?

Answered: 1 week ago