mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
IFT-300 Adapt Find in Files lesson samples to Python 2.7
IJ-CR-16198 GitOrigin-RevId: 54a7ee531d436430d0a27927e610471d36f7adfc
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1c1d590871
commit
bbb4d7ec3c
@@ -1,31 +1,31 @@
|
||||
from util.util import FRUITS
|
||||
from util import FRUITS
|
||||
|
||||
|
||||
class Warehouse:
|
||||
# Fruit name to amount of it in warehouse
|
||||
entry = {} # Apple, banana, etc...
|
||||
|
||||
def __init__(self) -> None:
|
||||
def __init__(self):
|
||||
for fruit in FRUITS:
|
||||
self.entry[fruit] = 0
|
||||
|
||||
# fruit name from util.FRUITS (mango, apple...)
|
||||
def add_fruits(self, fruit_name, quantity) -> None:
|
||||
def add_fruits(self, fruit_name, quantity):
|
||||
cur_quantity = self.entry.get(fruit_name)
|
||||
if cur_quantity is not None:
|
||||
self.entry[fruit_name] = cur_quantity + quantity
|
||||
else:
|
||||
raise KeyError(f"Not found fruit with name: {fruit_name}")
|
||||
raise KeyError("Not found fruit with name: " + fruit_name)
|
||||
|
||||
def take_fruit(self, fruit_name) -> bool:
|
||||
def take_fruit(self, fruit_name):
|
||||
cur_quantity = self.entry.get(fruit_name)
|
||||
if cur_quantity is None:
|
||||
raise KeyError(f"Not found fruit with name: {fruit_name}")
|
||||
raise KeyError("Not found fruit with name: " + fruit_name)
|
||||
elif cur_quantity > 0:
|
||||
self.entry[fruit_name] = cur_quantity - 1
|
||||
return True
|
||||
return False
|
||||
|
||||
def print_all_fruits(self) -> None:
|
||||
def print_all_fruits(self):
|
||||
for fruit, quantity in self.entry.items():
|
||||
print(f"{fruit}: {quantity}")
|
||||
print(fruit + ": " + str(quantity))
|
||||
@@ -1,4 +1,4 @@
|
||||
from warehouse.warehouse import Warehouse
|
||||
from warehouse import Warehouse
|
||||
|
||||
warehouse = Warehouse()
|
||||
warehouse.add_fruits('peach', 3)
|
||||
|
||||
Reference in New Issue
Block a user