Last active
January 30, 2020 18:42
-
-
Save rinterliche/e3da3193647d0ef21e6380f8f0ffd997 to your computer and use it in GitHub Desktop.
Python Kata
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
# ====================================== | |
# Specification | |
# ====================================== | |
# We are a small inn with a prime location that buy and sell only the finest goods. | |
# Unfortunately, our goods are constantly degrading in quality as they approach their sell by date. We | |
# have a system in place that updates our inventory for us. It was developed by a no-nonsense type named | |
# Leeroy, who has moved on to new adventures. | |
# - All items have a SellIn value which denotes the number of days we have to sell the item | |
# - All items have a Quality value which denotes how valuable the item is | |
# - At the end of each day our system lowers both values for every item | |
# Pretty simple, right? Well this is where it gets interesting: | |
# - Once the sell by date has passed, Quality degrades twice as fast | |
# - The Quality of an item is never negative | |
# - The Quality of an item is never more than 50 | |
# - Item named "Aged Brie" actually increases in Quality the older it gets | |
# - Item named "Sulfuras", being a legendary item, never has to be sold or decreases in Quality | |
# - Item named "Backstage passes", like "Aged Brie", increases in Quality as its SellIn value approaches; | |
# - Item named "Backstage passes" Quality increases by 2 when there are 10 days or less to sell and by 3 | |
# when there are 5 days or less to sell. | |
# Feel free to make any changes to the UpdateQuality method and add any new code as long as everything | |
# still works correctly. However, do not alter the Item class or Items property. | |
# Just for clarification, an item can never have its Quality increase above 50, however "Sulfuras" is a | |
# legendary item and as such its Quality is 80 and it never alters. | |
# Item Class is something like: | |
# class Item: | |
# def __init__(self, name, sell_in, quality): | |
# self.name = name | |
# self.sell_in = sell_in | |
# self.quality = quality | |
# def __repr__(self): | |
# return "%s, %s, %s" % (self.name, self.sell_in, self.quality) | |
class GildedRose(object): | |
def __init__(self, items): | |
self.items = items | |
def update_quality(self): | |
for item in self.items: | |
if item.name != "Aged Brie" and item.name != "Backstage passes": | |
if item.quality > 0: | |
if item.name != "Sulfuras": | |
item.quality = item.quality - 1 | |
else: | |
if item.quality < 50: | |
item.quality = item.quality + 1 | |
if item.name == "Backstage passes": | |
if item.sell_in < 11: | |
if item.quality < 50: | |
item.quality = item.quality + 1 | |
if item.sell_in < 6: | |
if item.quality < 50: | |
item.quality = item.quality + 1 | |
if item.name != "Sulfuras": | |
item.sell_in = item.sell_in - 1 | |
if item.sell_in < 0: | |
if item.name != "Aged Brie": | |
if item.name != "Backstage passes": | |
if item.quality > 0: | |
if item.name != "Sulfuras": | |
item.quality = item.quality - 1 | |
else: | |
item.quality = item.quality - item.quality | |
else: | |
if item.quality < 50: | |
item.quality = item.quality + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment