Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- def found_name_age(a: str, b: str):
- if a == '@' or a == '#':
- num = ''
- idx = b.index(a) + 1
- while True:
- if b[idx] == '|' or b[idx] == '*':
- break
- num += b[idx]
- idx += 1
- return num
- for _ in range(n):
- text = input()
- person = []
- i = 0
- while i < len(text) - 1:
- if text[i] == '@':
- name = found_name_age(text[i], text)
- person.append(name)
- i += len(name)
- elif text[i] == '#':
- age = int(found_name_age(text[i], text))
- person.append(age)
- i += len(str(age))
- if len(person) == 2:
- if str(person[1]).isdigit():
- print(f'{person[0]} is {person[1]} years old.')
- name = ''
- age = -111
- person = []
- else:
- print(f'{person[1]} is {person[0]} years old.')
- name = ''
- age = -111
- person = []
- i += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement