Answer to Question #327956 in Python for hari

Question #327956

Pager:

Imagine a paper with only one button. for the letter "A", you press the button one time, for "B", you press it 2 times for "E", you press it five times. for "G", it's pressed seven times, etc.

Given a string s, print the total number of times the button should be pressed

explanation: given string is abde. then the total no. of times the button pressed is 1+2+4+5=12

I/p: abde

O/p: 12

I/p: xyz

O/p: 75


1
Expert's answer
2022-04-12T16:15:15-0400
import string

answer = 0
for i in input("Input sting: ").lower():
    answer += string.ascii_lowercase.find(i) + 1

print(answer)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS