Advertisement
SimeonTs

SUPyF2 Text-Pr.-More-Ex. - 01. Extract Person Information

Oct 27th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. """
  2. Text Processing - More Exercises
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1741#0
  4.  
  5. SUPyF2 Text-Pr.-More-Ex. - 01. Extract Person Information
  6.  
  7. Problem:
  8. Write a program that reads N lines of strings and extracts the name and age of a given person.
  9. The name of the person will be between '@' and '|'. The person’s age will be between '#' and '*'.
  10. Example: "Hello my name is @Peter| and I am #20* years old."
  11. For each found name and age print a line in the following format "{name} is {age} years old."
  12.  
  13. Example:
  14. Input:
  15. 2
  16. Here is a name @George| and an age #18*
  17. Another name @Billy| #35* is his age
  18.  
  19. Output:
  20. George is 18 years old.
  21. Billy is 35 years old.
  22.  
  23. Input:
  24. 3
  25. random name @lilly| random digits #5* age
  26. @Marry| with age #19*
  27. here Comes @Garry| he is #48* years old
  28.  
  29. Output:
  30. lilly is 5 years old.
  31. Marry is 19 years old.
  32. Garry is 48 years old.
  33. """
  34. for text in range(int(input())):
  35.     line = [letter for letter in input()]
  36.     name = ''.join(line[(line.index("@") + 1):line.index("|")])
  37.     age = ''.join(line[(line.index("#") + 1):line.index("*")])
  38.     print(f"{name} is {age} years old.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement