Skip to content

Instantly share code, notes, and snippets.

@andriiburka
Created March 21, 2020 23:18
Show Gist options
  • Save andriiburka/b4cc94b1a295a98f6b0dcd554af18aab to your computer and use it in GitHub Desktop.
Save andriiburka/b4cc94b1a295a98f6b0dcd554af18aab to your computer and use it in GitHub Desktop.
75/100
import re
pattern = r"^>>([A-Za-z]+)<<(\d+.?\d+!\d+)$"
txt = ''''''
while True:
user_input = input()
if "Purchase" in user_input:
txt += "\n" + user_input
break
else:
txt += "\n" + user_input
txt = txt[1:]
data_tuple = re.findall(pattern, txt, re.M)
data_dict = {}
for device, value in data_tuple:
data_dict[device] = float(value.split("!")[0]) * float(value.split("!")[1])
print("Bought furniture:\n" +
"\n".join([key for key, value in data_dict.items()]) +
f"\nTotal money spend: {sum([value for key, value in data_dict.items()]):.2f}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment