How do I use the for loop in conjunction with other functions?

18 Views Asked by At

How do I use a for loop with range () iterate over the alphabet a to z (using Ord () to traverse and chr () to get the characters in the sentence only? I am supposed to display each letter in senetence and how many times each shows up.

Q1: Read a string (text) from the user and Display its length, Display how many 'a', 'b', 'c', ..., 'z' it has, case insensitive. Display the first word (before the first space) input:

msg = input('Enter a sentence: ')
print('Length: ',(len(msg)))
for letter in range(ord('a'), ord('z') +1):
    first_word = msg.split()[0]
print('The first word is: ', first_word)

output: Length: 13 The First word is: Hello I figured out how to display the length and the first word but not the middle part where I'm supposed to display how many 'a', 'b', 'c' there are in the sentence. Please Help

0

There are 0 best solutions below