Question: NOTE: All code should be in python. The question may seem like its multiple,but it is actually only one question. You may not use any
NOTE: All code should be in python. The question may seem like its multiple,but it is actually only one question. You may not use any functions from external modules loaded by 'import.' In addition, you may not use dictionaries, list comprehensions, or other Python language features not yet taught in this class. The point of these exercises is to practice very basic components of programming.
1. Write a function, hw3q1(inputString), that takes as input a string of lowercase letters and prints three things: the lexicographically second smallest letter (a < b < ... < z), the third smallest letter, and the most common letter along with how many times it occurs. You may not assume that the string contains at least three different characters (or even any characters at all). If fewer than three different letters appear in the string, print something appropriate for the third smallest (e.g. "There is no third smallest letter."). Similarly, do something appropriate if fewer than two different letters appear. If two or more letters tie for most common, you may choose any one of them. For example:
>>> hw3q1('aaczzcqzqqqzqc') In 'aaczzcqzqqqzqc', the second smallest letter is 'c', the third smallest letter is 'q', and the most common letter is 'q', occurring 5 times >>> hw3q1("aaaaba") In 'aaaaba', the second smallest letter is 'b', there is no third smallest letter, and the most common letter is 'a', occurring 5 times NOTE: you may not use built-in min, max, sort, or sorted functions. You may not use any built-in string methods. You may use [] to access single characters of a string, if you wish. Use one or more simple loops, and simple comparison (<,>, ==, !=) operators only. Add a function hw3q2(num) that takes a positive integer as input and returns a list of that number's prime divisors. You may copy and use the numIsPrime function developed in class if you wish. For example:
>>> hw3q2(36) [2,3] >>> hw3q2(23) [23] >>> >>> hw3q2(5003*5003+1) [2, 5, 2503001] >>> hw3q2(4) [2] >>> hw3q2(1) []
Add function, hw3q3(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 sublists and the sublist containing that maximum.
the sublist list whose elements sum to the greatest total
If there is a tie for maximum, you may print any one of the sublists that contains that maximum. If there is no maximum, hw3q3 should print an appropriate message. If there is a tie for greatest sublist sum, you may print any one of the sublists having that sum. The sum of items in an empty list should be treated as 0. For example:
>>>hw3q3([[3, 7], [9, 4, 6]]) In [[3, 7], [9, 4, 6]] the max item is 9 and is found in sublist [9, 4, 6] and [9, 4, 6] has the maximum sum with a total of 19
You should use nested loops for this problem, an outer loop iterating over items (sublists) of the main list, and an inner loop stepping over items (numbers) in the sublists. Only simple comparisons and arithmetic operations should be used. Once again, you may not use built-in functions min, max, sort or sorted for this problem. Also, you many not use Python's "sum" function. Add functions testQ1(), testQ2(), and testQ3() that test your Q1, Q2, and Q3 functions on a variety of input values.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
