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

Using python3 1. Write a function, stringStats(inputString), that takes as input

ID: 3667963 • Letter: U

Question

Using python3

1. Write a function, stringStats(inputString), that takes as input a string of letters (possibly upper and lower case) and prints three things: the lexicographically smallest letter, the second smallest letter, and the most common letter. You may assume that the input string contains at least two different letters. If two or more letters tie for most common, you may choose any one of them. Ignore case when determining these values. That is, 'A' and 'a' are both considered occurrences of the letter a. For example: >>> stringStats('aaZZqzqqCzCC') In 'aaZZqzqqCzCC', the smallest letter is 'a', the second smallest letter is 'c', and the most common letter is 'z' >>> stringStats('Dg') In 'Dg', the smallest letter is 'd', the second smallest letter is 'g', and the most common letter is 'd' NOTE: you may not use built-in min, max, sort, or sorted functions. You may, however, use built-in string methods.

2. Write a function divisorList(num) that takes a positive integer as input and returns a list of that number's divisors (including 1 and itself). Thus, divisorList(36) would return [1,2,3,4,6,9,12,18,36].

3. Write function, listyMax(listOfLists), that takes as input a list of zero or more sublists each containing zero or more numbers, and determines and prints the maximum number among all of the lists and the sublist containing that maximum number. You may assume there is no tie for the maximum. I.e, if there is a maximum, it is unique. If, however, there is no maximum, listyMax should print an appropriate message. For example: >>>listyMax([[7,6], [4, 9, 6]]) In [[7, 6], [4, 9, 6]] the max item is 9 and is found in sublist [4, 9, 6] NOTE: You may not use built-in functions min, max, sort or sorted for this problem. You need to step through the lists to find the appropriate items and do necessary basic comparisons.

4. Write functions testQ1(), testQ2(), and testQ3() that test your Q1, Q2, and Q3 functions on a variety of input values.

Explanation / Answer

Multiple Questions : Answering 1st :

------------------------------

def stringStats(inputString) :
    first ="z"
    second = "z"
    max = -1
    c = ''
    count = [0] * 256
    for letter in inputString.lower() :
        count[ord(letter)]+=1;
        if(letter < first) :
            second = first
            first = letter
        elif (letter < second and letter != first) :
            second = letter
    for letter in inputString.lower():
        if max < count[ord(letter)]:
            max = count[ord(letter)]
            c = letter
    print "The smallest letter is",first
    print "The second smallest letter is",second
    print "The most common letter is",c
  
s = raw_input("enter string")
print
stringStats(s)

---------------------------------

enter string : aaZZqzqqCzCC
The smallest letter is a
The second smallest letter is c
The most common letter is z

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote