Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- materials = [int(x) for x in input().split()]
- #print(materials)
- magic_level = deque(int(x) for x in input().split())
- #print(magic_level)
- pattern = {
- 150: 'Doll',
- 250: 'Wooden train',
- 300: 'Teddy bear',
- 400: 'Bicycle',
- }
- counters = {}
- total_magic_lvl: int = 0
- while True:
- if not materials or not magic_level:
- break
- material = materials.pop()
- m_lvl = magic_level.popleft()
- total_magic_lvl = material * m_lvl
- if total_magic_lvl > 0:
- if total_magic_lvl in pattern.keys():
- if pattern[total_magic_lvl] not in counters.keys():
- counters[pattern[total_magic_lvl]] = 1
- continue
- counters[pattern[total_magic_lvl]] += 1
- else:
- # If the product of the operation is a negative number, then you have to sum the values together,
- # remove them both from their positions and the result should be added to the materials.
- if total_magic_lvl < 0:
- result_after_negative_total_magic_lvl = material + m_lvl
- materials.append(result_after_negative_total_magic_lvl)
- # If the product doesn’t equal one of the magic levels in the table and is a positive number,
- # remove only the magic value and increase the material value with 15.
- if total_magic_lvl > 0:
- material += 15
- materials.append(material)
- # If the magic or material (or both) equals 0,
- # remove it (or both) and continue crafting the presents.
- if total_magic_lvl == 0:
- if material != 0:
- materials.append(material)
- if m_lvl != 0:
- magic_level.appendleft(m_lvl)
- else:
- # If the product of the operation is a negative number, then you have to sum the values together,
- # remove them both from their positions and the result should be added to the materials.
- if total_magic_lvl < 0:
- result_after_negative_total_magic_lvl = material + m_lvl
- materials.append(result_after_negative_total_magic_lvl)
- # If the product doesn’t equal one of the magic levels in the table and is a positive number,
- # remove only the magic value and increase the material value with 15.
- elif total_magic_lvl > 0:
- material += 15
- materials.append(material)
- # If the magic or material (or both) equals 0,
- # remove it (or both) and continue crafting the presents.
- else:
- if material:
- materials.append(material)
- elif m_lvl:
- magic_level.appendleft(m_lvl)
- if 'Doll' and 'Wooden train' in counters.keys() or 'Teddy bear' and 'Bicycle' in counters.keys():
- print("The presents are crafted! Merry Christmas!")
- else:
- print("No presents this Christmas!")
- if materials or magic_level:
- materials = materials[::-1]
- if materials:
- print(f"Materials left: {', '.join(str(x) for x in materials)}")
- if magic_level:
- print(f"Magic left: {', '.join(str(x) for x in magic_level)}")
- #On the next lines print the presents you have crafted at least once, ordered alphabetically in the format:
- #"{toy name}: {amount}"
- #print(counters)
- for key, value in sorted(counters.items(), key=lambda x: x[0]):
- print(f"{key}: {value}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement