Computer Science, asked by roshanisati, 11 months ago

Question 2
The potential of a word is found by adding the ASCII value of the alphabets.
(ASCII values of A to Z are 65 to 90).
Example: BALL
Potential = 66 +65 + 76 + 76 = 283
Write a program to accept a sentence which may be terminated by either".","? "or"!"only.
The words of sentence are separated by single blank space and are in UPPER CASE. Decode the
words according to their potential and arrange them in ascending order of their potential strength.
Test your program with the following data and some random data:
Example 1:
INPUT:
HOW DO YOU DO?
OUTPUT:
HOW = 238
DO = 147
YOU = 253
DO = 147
DO DO HOW YOU​

Answers

Answered by poojan
3

Decoding the  words according to their potential and arrange them in ascending order of their potential strength.

Language using : Python Programming

Program :

x=input()

x=x[:-1]

x=x.split(" ")

sum=0

for i in x:

   for j in list(i):

       sum=sum+ord(j)

   print(i," = ",sum)

   sum=0

x=sorted(x)

for i in x:

   print(i,end=" ")

Input :

HOW DO YOU DO?

Output :

HOW  =  238

DO  =  147

YOU  =  253

DO  =  147

DO DO HOW YOU

Explanation :

First, we need to take an input statement that terminates with either ".", "? "or "!" only. And then, we remove those terminations with slicing and them prepare a list of each individual string in the statement by stripping the statement using space.

After the strings list is formed, we further write inner loop that runs on list of each string again. Ord() helps in converting the string into their ASCII values and we calculate sum of ASCII values of the letters in each string and print them. Then, we sort the strings using sorted() method and print them in same line. That's it!

Note : I have added the attachments of the interpretation and the execution of programs with their outputs. Take a look!

Quick Tip : In python, you must and should follow Indentation. Following the indentation property in any programming language will help you in quickly analysing the code, if an error occurs.

Similar questions which may help you.

  • What are the advantages of Python Programming?

        brainly.in/question/11007952

  • Calculating the ASCII value of a character.

       https://brainly.in/question/14340040

Thank you so much for dropping by. Hope it helps you.

Attachments:
Similar questions