Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

) Using the list a defined below, write a Python program that will Display a string that consists of the first letter and last letter

) Using the list a defined below, write a Python program that will

Display a string that consists of the first letter and last letter from each of the names in the list a

The output should look like EdAsNn etc. use the + operator or the append() function from prior lab

Display list a with all the names reversed that is display

dilcuE, sedemihcrA etc.

Display the total number of characters in the list a Hint: Sum the lengths of each name In the prior lab we determined the number of vowels in the list. For this lab, display the number of consonants (non-vowels) Use your result from 3. to assist in the calculations Display the number of each letter in the list NOTE ignore case A and a are to be considered the same. See code below starts with alphaCnt (There are eight A in the list ) as well as the code

print('1 ',ord('A')-ord('A'))

print('2 ',ord('B')-ord('A'))

print('3 ',ord('C')-ord('A'))

print('26 ',ord('Z')-ord('A'))

Suggested output:

Number of A == 8

Number of B == 2

Number of Z == 0

Display the average length of the strings in the list. Remember to use the results from 3 and divide by n

#CSC120Lab08Template

n = 15 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

OUTPUT:

0 ['Euclid', 'Archimedes', 'Newton', 'Descartes', 'Fermat', 'Turing', 'Euler', 'Einstein', 'Boole', 'Fibonacci', 'Nash', 'Wiles', 'Cantor', 'Gauss', 'Plato']

1 Euclid 6 E d

2 Archimedes 10 A s

3 Newton 6 N n

4 Descartes 9 D s

5 Fermat 6 F t

6 Turing 6 T g

7 Euler 5 E r

8 Einstein 8 E n

9 Boole 5 B e

10 Fibonacci 9 F i

11 Nash 4 N h

12 Wiles 5 W s

13 Cantor 6 C r

14 Gauss 5 G s

15 Plato 5 P o

the number of i is 8

T ord value == 19

u ord value == 20

r ord value == 17

i ord value == 8

n ord value == 13

g ord value == 6

A ord value == 0

a ord value == 0

b ord value == 1

c ord value == 2

d ord value == 3

e ord value == 4

f ord value == 5

g ord value == 6

h ord value == 7

i ord value == 8

j ord value == 9

k ord value == 10

l ord value == 11

m ord value == 12

n ord value == 13

o ord value == 14

p ord value == 15

q ord value == 16

r ord value == 17

s ord value == 18

t ord value == 19

u ord value == 20

v ord value == 21

w ord value == 22

x ord value == 23

y ord value == 24

z ord value == 25

alphaCnt -- [2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 2, 2, 1, 1, 1, 1, 1]

NOTE: alphaCnt[0] == 2 the number of A in s = 'TuringAabcdefghijklmnopqrstuvwxyz'

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

More Books

Students also viewed these Databases questions

Question

Connect with your audience

Answered: 1 week ago