Skip to content

Commit b59b267

Browse files
committed
buy flowers
1 parent 360ed81 commit b59b267

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

newcodes/answers/q65.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python
2+
# coding=utf-8
3+
4+
class Flower:
5+
def __init__(self, price_table):
6+
self.price_table = price_table
7+
8+
def buy_flower(self, count, name):
9+
if name in self.price_table:
10+
self.count = count
11+
self.name = name
12+
self.sales = self.price_table[self.name] * self.count
13+
else:
14+
self.sales = 0
15+
16+
def total(self):
17+
return self.sales
18+
19+
if __name__ == "__main__":
20+
price = {"petunia":50, "pansy":15, "rose":75, "violet":20, "carnation":80}
21+
print(price)
22+
f = Flower(price)
23+
while True:
24+
my = input("input the name of flower:('q'-exit)")
25+
if my == "q":
26+
print("Bye")
27+
break
28+
else:
29+
count = int(input("input the number that you want to buy_flower:"))
30+
f.buy_flower(count, my)
31+
print("You should pay:{0}".format(round(f.total(), 2)))
32+

0 commit comments

Comments
 (0)