Reputation: 1
I want a function that loops through the text and print out the letters alone and the numbers alone.
I have
function("A10")
The result should be:
A
10
For:
function("A1B3")
The result should be :
A
1
B
3
For C12H30
The result should be :
C
12
H
30
Thanks
Upvotes: 0
Views: 94
Reputation: 46
given_string = "A10"
for i in string:
if i.isalpha():
print(i)
else:
print(i, end='')
Upvotes: 3
Reputation: 24133
You could index the first value:
>>> name[0]
'A'
You could slice the rest:
>>> name[1:]
'10'
In code:
print(name[0])
print(name[1:])
Output:
A
10
Upvotes: 1
Reputation: 1
when you use "for loop" it loop letters in the word, every letter in a single line
A
1
0
Upvotes: -2