Product of the String
You are given an alphanumeric string S.Write a program to multiply all the charcters(except trailing zeroes) in S and print the output.
Rules for multiplication:
Input
The first line contains a string S.
Output
The output should be a integer denoting the product of characters.
Explanation
For N = 123a4
ASCII value of a is 97.
Product of digits of ASCII value of a is 9 *7 = 63.
Therefore the product of characters is 1*2*3*4*63*4 = 1512.
Sample Input1
123a4
Sample Output1
1512
def mult_str(string):
j = 1
for i in string:
if i.isalpha() == True:
for k in str(ord(i)):
j = j * int(k)
elif i.isdigit() == True:
j = j * int(i)
return j
mult_str('123a4')
1512
Comments
Leave a comment