Advertisement
Guest User

Untitled

a guest
Nov 18th, 2023
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. import re
  2.  
  3. user_input = input()
  4.  
  5. #dict_of_names = {}
  6.  
  7. pattern = r"^\%([A-Z][a-z]+)\%[^|$%.]*\<(\w+)\>[^|$%.]*\|(\d+)\|[^|$%.]*?(\d+\.*\d+)\$$"
  8.  
  9. #matches = re.findall(pattern, user_input)
  10.  
  11. #while matches == []:
  12. #    user_input = input()
  13. #    matches = re.findall(pattern, user_input)
  14.  
  15. #matches = [x for x in matches[0]]
  16.  
  17. total = 0
  18.  
  19. while user_input != 'end of shift':
  20.     if re.search(pattern, user_input) is None:
  21.         user_input = input()
  22.         continue
  23.  
  24.     matches = re.findall(pattern, user_input)
  25.  
  26.     matches = [x for x in matches[0]]
  27.     #if matches[0] not in dict_of_names.keys():
  28.     #    dict_of_names[matches[0]] = [matches[1], int(matches[2]), float(matches[3])]
  29.     #else:
  30.     #    pass
  31.  
  32.     #person = matches[0]
  33.     #total += int(dict_of_names[person][1]) * float(dict_of_names[person][2])
  34.     total += int(matches[2]) * float(matches[3])
  35.     print(
  36.         f'{matches[0]}: {matches[1]} - {(int(matches[2]) * float(matches[3])):.2f}')
  37.     user_input = input()
  38.  
  39. #for person in dict_of_names.keys():
  40. #    print(
  41. #        f'{person}: {dict_of_names[person][0]} - {(int(dict_of_names[person][1]) * float(dict_of_names[person][2])):.2f}')
  42.  
  43. print(f'Total income: {total:.2f}')
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement