1.
Write a code that asks the user to enter a sentence. Then process the sentence and let the user know which alphabets/numbers/symbols are used in the sentence and how many times.
please use python
CODE:
#dictionary which will hold all the unique characters as the
keys and its frequency as its value
freq = {}
#asking a sentence from an user
sentence = input('Enter a sentence: ')
#traversing each character in the sentence
for i in sentence:
#if a character is not present in the keys of the dictionary
if(i not in freq.keys()):
#its value is initialized to 0
freq[i] = 0
#then the value is incremented at its respective key value
freq[i] += 1
#printing the key-value pairs will give the frequency of each
character in the sentence
for i in freq.keys():
print('Frequency of {} in the sentence:
{}'.format(i,str(freq[i])))
__________________________________________________
CODE IMAGES AND OUTPUT:
___________________________________________
Feel free to ask any images in the comments section
Thank You!
Get Answers For Free
Most questions answered within 1 hours.