Advertisement
DiYane

Extract Person Information

Sep 26th, 2023
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. def extract_information(string):
  2.     name = ''
  3.     age = ''
  4.     for index, char in enumerate(string):
  5.         if char == '@':
  6.             while True:
  7.                 index += 1
  8.  
  9.                 if string[index] == '|':
  10.                     break
  11.  
  12.                 name += string[index]
  13.         elif char == '#':
  14.             while True:
  15.                 index += 1
  16.  
  17.                 if string[index] == '*':
  18.                     break
  19.  
  20.                 age += string[index]
  21.  
  22.     return f'{name} is {age} years old.'
  23.  
  24. string_lines = int(input())
  25.  
  26. for person_information in range(string_lines):
  27.     information = input()
  28.     print(extract_information(information))
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement