Dana row, items of which are any characters, how to calculate the amount of numbers in the line
Follow the code
STR1 = STR (INPUT ())
Print (STR1)
k = 0.
For Elem in Str1:
IF Elem & GT; = "0" and Elem & Lt; = "9":
k = k + 1
Print (Elem)
Print ("k =", k)
Answer 1
You need to check whether it is possible to make a number from the symbol, this is done like this:
elem.isdigit ()
you need to find the amount and not the quantity:
k = k + 1
Change on:
k + = int (elem)
code should be:
STR1 = STR (INPUT ())
Print (STR1)
k = 0.
For Elem in Str1:
IF Elem.isdigit ():
K + = int (Elem)
Print (Elem)
Print ("k =", k)
Answer 2
import re
a = input ('')
Digits = Re.Findall ("\ d", a)
IF Not Digits:
Print ('numbers not found')
ELSE:
Print (Eval ('+'. Join (Digits)))