RobaLob Dob
@RobaLobDob
Hello Lloyd
how do you get code to count how many numbers are in a string
girianshiido Here is another way to do it in Python:
my_string = input('Enter your string:')
print(my_string.translate({i+48:57 for i in range(9)}).count('9'))
Basically, you convert all the digits from 0 to 8 in you string to nines and then count the nines. The small dictionary is just here to convert each digit from '0' (character number 48) to '8' (character number 56) to a '9' (character number 57). You can create this dictionary using the maketrans method :
tab = maketrans('012345678', '9'*9)
my_string4 years ago
ash15khng In what language do you want to do this? In Python you can use something like
string = "abcdef54w6ed7fuyigy86giug75r54f789yu9ou2j89wrhg" # random string
counter = 0
for char in string:
if char == '0' or char == '1' or char == '2' or char == '3' or char == '4' or char == '5' or char == '6' or char == '7' or char == '8' or char == '9':
counter += 1
print(counter)
`4 years ago