Question: Using the list names and alphaCount defined below, write a Python program that will Display a string that consists of the first letter and last
Using the list names and alphaCount defined below, write a Python program that will
Display a string that consists of the first letter and last letter from each of the entries in n the list names
The output should look like EdAsNn etc. use the + operator or the append() function from prior lab
Display list names with all the names reversed that is display
dilcuE, sedemihcrA etc.
Display the total number of characters in the list Hint: Sum the lengths of each name
In the prior lab we determined the number of vowels in a list. For this lab, display the number of consonants (non-vowels) Use your result from 3, and subtract number of vowels
Display the list alphaCount which contains the number of each letter in the list NOTE case A and a are to be considered the same. See code below that starts with alphaCnt (There are eight A in the list ) as well as the code
alphaCount == [8, 2, . 0] i.e there are 8 A or a , there are 2 B or b . There are 0 Z or z
Display the average length of the strings in the list. Remember to use the results from 3 and divide by the number of names
use len() function
Once you have populated alphaCnt (== number of letters in the list names) display the letter that occurs the most in alphaCnt
Using the max function max(alphaCount) will return the largest number in alphaCount but not
the character associated with the max value ?
Sort the list names and display the median name
python code:
a = ["Euclid", "Archimedes", "Newton", "Descartes", "Fermat", "Turing", "Euler", "Einstein", "Boole", "Fibonacci", "Nash", "Wiles", "Cantor", "Gauss", "Plato"] # Initial list n == 15 print('0', a) j = 0 cnt = 1 for k in a: print(cnt, k, len(k), k[j], k[len(k) - 1]) # first letter and last letter in name cnt = cnt + 1 s = 0 letter = 'i' for name in a: r = name.count(letter) s = s + r print("the number of i is ", s) s = 'TuringAabcdefghijklmnopqrstuvwxyz' print(' ord values for characters ') print('1 ',ord('A')-ord('A')) print('2 ',ord('B')-ord('A')) print('3 ',ord('C')-ord('A')) print('26 ',ord('Z')-ord('A')) alphaCnt = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # 26 zeros store n of each uppercase letter for ch in s: ## looping in this way, ch will be 'T', then 'u', ... through the string x = ord(ch.upper()) - ord('A') # to uppercase; determine place in alphaCnt print(ch, ' ord value == ', x) alphaCnt[x] = alphaCnt[x] + 1 print('alphaCnt == ', alphaCnt) # number of A, B etc characters in s Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
