Created
March 21, 2020 23:18
-
-
Save andriiburka/b4cc94b1a295a98f6b0dcd554af18aab to your computer and use it in GitHub Desktop.
75/100
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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