From 15b3cda43a3d021e36915e2b3076aac91b77bbb6 Mon Sep 17 00:00:00 2001 From: Bharani Date: Sun, 3 Apr 2022 18:07:53 +0530 Subject: [PATCH 1/5] new file: Bharani_Flask_blog/__pycache__/flaskblog.cpython-310.pyc new file: Bharani_Flask_blog/__pycache__/forms.cpython-310.pyc new file: Bharani_Flask_blog/flaskblog.py new file: Bharani_Flask_blog/forms.py new file: Bharani_Flask_blog/static/main.css new file: Bharani_Flask_blog/templates/home.html new file: Bharani_Flask_blog/templates/layout.html new file: Bharani_Flask_blog/templates/post_creation.html new file: Bharani_Flask_blog/templates/posts.html --- .../__pycache__/flaskblog.cpython-310.pyc | Bin 0 -> 1214 bytes .../__pycache__/forms.cpython-310.pyc | Bin 0 -> 612 bytes Bharani_Flask_blog/flaskblog.py | 51 +++++++++++ Bharani_Flask_blog/forms.py | 9 ++ Bharani_Flask_blog/static/main.css | 80 ++++++++++++++++++ Bharani_Flask_blog/templates/home.html | 10 +++ Bharani_Flask_blog/templates/layout.html | 58 +++++++++++++ .../templates/post_creation.html | 40 +++++++++ Bharani_Flask_blog/templates/posts.html | 15 ++++ 9 files changed, 263 insertions(+) create mode 100644 Bharani_Flask_blog/__pycache__/flaskblog.cpython-310.pyc create mode 100644 Bharani_Flask_blog/__pycache__/forms.cpython-310.pyc create mode 100644 Bharani_Flask_blog/flaskblog.py create mode 100644 Bharani_Flask_blog/forms.py create mode 100644 Bharani_Flask_blog/static/main.css create mode 100644 Bharani_Flask_blog/templates/home.html create mode 100644 Bharani_Flask_blog/templates/layout.html create mode 100644 Bharani_Flask_blog/templates/post_creation.html create mode 100644 Bharani_Flask_blog/templates/posts.html diff --git a/Bharani_Flask_blog/__pycache__/flaskblog.cpython-310.pyc b/Bharani_Flask_blog/__pycache__/flaskblog.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..41e85e5524aa90073ff057a2fae5cea12524091c GIT binary patch literal 1214 zcmZ{kOK;RL5P;)6cC*`k_5A=Oi`z=jRz+M8LVcjBNL5wQR!GrGQFiU_hE3v?Yy$PJ=}qwRhYG7)kbJCO5LRRLcg7ikebwC70NW&+LYr61Ez@9`VY9iV&P!~r zZ^}bne%)a6Y~h>$&*DMen@eAT*l1eX*^Yv=uj`U0j7wkfcn}4O>tZG&|5(VTts5_S zH%yfbR49^dA!A+I72R;8P96;y_-}MNB1=@h>h6nlq!l-NfeeyRyW2vjb`V9whp&1( zp{HRK(eWZZ4OFK`0~&=VoF0!IX^hrkWn&=2h^{_*K-boQr4VGQC!}^%s3M^3h(z&3 z=?R4J2auRE?d)-&)y{61WN(H$yJ4TFR0*0TVUjAKfMlma_QRx0Pq<9sSX3NCesHHj z!l**Vw&X#dh6-R+k0$)|8fFb)uE@&JS?P(Gcd(Q--LD=}#0 zx94w0qT3pu#9wP2#paNSV{Y6s z=H3VOlH|ZJaNwmXwJL~Q>C$*E8Q6l*0fLI(| z|5IG}I^tB~WlQ`K$RY|CogiWo#N79_6$}RXRcc3yO!2(>c@;*vEtw^^61z`h!Lo=y mBM>lM1u-|AH9qsSpj=j5q1o=m$v8S%7gGq zxpLwW;KVqo%38{3{xhDL-&nEJ>6qYoo*!MDP(mJ~*gPqU@A&y>B#~4TLxIxhCps|< zm`Ncu9C#mNIx{)slpGM5N`6NqS9Hywkl7h2^C#>=O4^NPy7pHy>rBbIcW1#h?Q+&A zEm5p4OcMq%Jy(Ci52xy0V%=oF4)v+JSv5|{%h+u5{D=LFQAL1C0*PXhs&q}3R3`Tc zaFt26p>tKpbWLF-IRa)~F}FTMFyQA+(5j>`zO8j5>tLOSe9yK)wV_Mnz2kD+6+*PN zQ9^WMA&iwP9sP+AH>+9?8OM;vWoSAcVpGSXpI;8WT;zt#_lrLe_dec^=H=twm+F^S z&R2)?YG3)QV6UtG>BLWMm(?w%8rzCb)dGqA?)6`nV_lr&3p54UqFZ!A`{;2wg3%(r zyZ9XzF2OwH=*7x`Fmm*0u>CK-`?h+|-#2;#9J~)$))ile-M`^qGz_1R9UQ&GUI9uy Bm23b2 literal 0 HcmV?d00001 diff --git a/Bharani_Flask_blog/flaskblog.py b/Bharani_Flask_blog/flaskblog.py new file mode 100644 index 0000000..5d53c24 --- /dev/null +++ b/Bharani_Flask_blog/flaskblog.py @@ -0,0 +1,51 @@ +from flask import Flask, render_template, url_for, flash, redirect +from forms import PostForm +from datetime import datetime + +app = Flask(__name__) +app.config['SECRET_KEY'] = '5791628bb0b13ce0c676dfde280ba245' +date = datetime.now() +blogposts = [ + { + 'author': 'Bharani', + 'title': 'Football', + 'content': 'When will Bharani watch a live football match', + 'date_posted': date.strftime("%d/%m/%y") + }, + { + 'author': 'Netra', + 'title': 'Linux', + 'content': 'Likes to uninstall a working version of linux and then break it with new', + 'date_posted': date.strftime("%d/%m/%y") + }, + { + 'author': 'Brinda', + 'title': 'Food In India', + 'content': 'Likes to try out new dish', + 'date_posted': date.strftime("%d/%m/%y") + } +] + + +@app.route("/") +@app.route("/home") +def home(): + return render_template('home.html', posts=blogposts, title='Home') + + +@app.route("/post") +def posts(): + return render_template('posts.html', posts=blogposts, title='Posts') + + +@app.route("/post_creation", methods=['GET', 'POST']) +def post_creation(): + form = PostForm() + if form.validate_on_submit(): + flash('Your post is done') + return redirect(url_for('home')) + return render_template('post_creation.html', title='Post Creation', form=form, posts=posts) + + +if __name__ == '__main__': + app.run(debug=True) diff --git a/Bharani_Flask_blog/forms.py b/Bharani_Flask_blog/forms.py new file mode 100644 index 0000000..a024d77 --- /dev/null +++ b/Bharani_Flask_blog/forms.py @@ -0,0 +1,9 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, SubmitField, TextAreaField +from wtforms.validators import DataRequired + + +class PostForm(FlaskForm): + title = StringField('Title', validators=[DataRequired()]) + content = TextAreaField('Content', validators=[DataRequired()]) + submit = SubmitField('Post') diff --git a/Bharani_Flask_blog/static/main.css b/Bharani_Flask_blog/static/main.css new file mode 100644 index 0000000..a0ef716 --- /dev/null +++ b/Bharani_Flask_blog/static/main.css @@ -0,0 +1,80 @@ +body { + background: #fafafa; + color: #333333; + margin-top: 5rem; +} + +h1, h2, h3, h4, h5, h6 { + color: #444444; +} + +.bg-steel { + background-color: #800000; +} + +.site-header .navbar-nav .nav-link { + color: #ffa500; +} + +.site-header .navbar-nav .nav-link:hover { + color: #ffffff; +} + +.site-header .navbar-nav .nav-link.active { + font-weight: 500; +} + +.content-section { + background: #deb887; + padding: 10px 20px; + border: 1px solid #dddddd; + border-radius: 3px; + margin-bottom: 20px; +} + +.article-title { + color: #444444; +} + +a.article-title:hover { + color: #000000; + text-decoration: none; +} + +.article-content { + white-space: pre-line; +} + +.article-img { + height: 65px; + width: 65px; + margin-right: 16px; +} + +.article-metadata { + padding-bottom: 1px; + margin-bottom: 4px; + border-bottom: 1px solid #e3e3e3 +} + +.article-metadata a:hover { + color: #333; + text-decoration: none; +} + +.article-svg { + width: 25px; + height: 25px; + vertical-align: middle; +} + +.account-img { + height: 125px; + width: 125px; + margin-right: 20px; + margin-bottom: 16px; +} + +.account-heading { + font-size: 2.5rem; +} \ No newline at end of file diff --git a/Bharani_Flask_blog/templates/home.html b/Bharani_Flask_blog/templates/home.html new file mode 100644 index 0000000..0e769e4 --- /dev/null +++ b/Bharani_Flask_blog/templates/home.html @@ -0,0 +1,10 @@ +{% extends "layout.html" %} +{% block content %} + {% for post in posts %} + + {% endfor %} +{% endblock content %} diff --git a/Bharani_Flask_blog/templates/layout.html b/Bharani_Flask_blog/templates/layout.html new file mode 100644 index 0000000..1f4c9d0 --- /dev/null +++ b/Bharani_Flask_blog/templates/layout.html @@ -0,0 +1,58 @@ + + + + + + + + + + {% if title %} + Flask Blog - {{ title }} + {% else %} + Flask Blog + {% endif %} + + + +
+
+
+ {% block content %}{% endblock %} +
+ + + + + + \ No newline at end of file diff --git a/Bharani_Flask_blog/templates/post_creation.html b/Bharani_Flask_blog/templates/post_creation.html new file mode 100644 index 0000000..bc265ae --- /dev/null +++ b/Bharani_Flask_blog/templates/post_creation.html @@ -0,0 +1,40 @@ +{% extends "layout.html" %} +{% block content %} +
+
+ {{ form.hidden_tag() }} +
+ Create a new Post +
+ {{ form.title.label(class="form-control-label") }} + {% if form.title.errors %} + {{ form.title(class="form-control form-control-lg is-invalid") }} +
+ {% for error in form.title.errors %} + {{ error }} + {% endfor %} +
+ {% else %} + {{ form.title(class="form-control form-control-lg") }} + {% endif %} +
+
+ {{ form.content.label(class="form-control-label") }} + {% if form.content.errors %} + {{ form.content(class="form-control form-control-lg is-invalid") }} +
+ {% for error in form.content.errors %} + {{ error }} + {% endfor %} +
+ {% else %} + {{ form.content(class="form-control form-control-lg") }} + {% endif %} +
+
+
+ {{ form.submit(class="btn btn-outline-info") }} +
+
+
+{% endblock content %} \ No newline at end of file diff --git a/Bharani_Flask_blog/templates/posts.html b/Bharani_Flask_blog/templates/posts.html new file mode 100644 index 0000000..0cceb7f --- /dev/null +++ b/Bharani_Flask_blog/templates/posts.html @@ -0,0 +1,15 @@ +{% extends "layout.html" %} +{% block content %} + {% for p in posts %} + + {% endfor %} +{% endblock content %} From 13016916d758588b43fc17cc6878e80c3fdaa042 Mon Sep 17 00:00:00 2001 From: Bharani Date: Sun, 3 Apr 2022 18:47:31 +0530 Subject: [PATCH 2/5] new file: Bharani_Vending_Machine/stock.py --- Bharani_Vending_Machine/stock.py | 134 +++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 Bharani_Vending_Machine/stock.py diff --git a/Bharani_Vending_Machine/stock.py b/Bharani_Vending_Machine/stock.py new file mode 100644 index 0000000..2d0695a --- /dev/null +++ b/Bharani_Vending_Machine/stock.py @@ -0,0 +1,134 @@ +class Stock: + counter = 0 + stock_set = set() + def __init__(self, stock_code, desc, price, available): + self.stock_code = stock_code + self.desc = desc + self.price = price + self.available = available + Stock.counter += 1 + Stock.stock_set.add(self.desc) + + def sell_price(self): + sp = round(self.price, 2) + print('cost = $', sp) + + def label(self): + print(f"{self.desc} costs you {self.price}") + + def sale(self, discount): + new_sp = round(self.price * (1 - discount), 2) + print('the discounted price of {} is $ {}'.format((self.stock_code, self.desc), new_sp)) + return new_sp + +class Chocolate(Stock): + category = 'chocolate' + def __init__(self, stock_code, desc, price, available): + super().__init__(stock_code, desc, price, available) + + def __repr__(self): + print("You have chosen = {self.label}") + + +class Chips(Stock): + category = 'chips' + + def __init__(self, stock_code, desc, price, packet_size, flavour, available): + Stock.__init__(self, stock_code, desc, price, available) + self.packet_size = packet_size + self.flavour = flavour + + def __repr__(self): + print("You have chosen = {self.label}") + + def one_for_one(self): + # buy one get one offer + sp = round(self.price, 2) + print('Buy two packets of {} and get one free. You pay {}'.format(self.packet_size, sp)) + + +class Canned(Stock): + category = 'cans' + + def __init__(self, stock_code, desc, price, volume, available): + Stock.__init__(self, stock_code, desc, price, available) + self.volume = volume + + def label(self): + print(f'{self.desc}') + self.sell_price() + + def apply_discount(self, discount): + new_sp = self.sale(discount) + print('Price reduced ! you save = $ ', self.price - new_sp) + + +class Vending_Machine: + def __init__(self): + self.money = 0 + self.products = {} + + def stock_details(self, product): + d2 = {} + d2[product.desc] = {} + d2[product.desc]['price'] = product.price + d2[product.desc]['quantity'] = product.available + if product.stock_code == 'Can': + d2[product.desc]['volume'] = product.volume + self.products.setdefault(product.stock_code, {}).update(d2) + elif product.stock_code == 'Chips': + d2[product.desc]['flavour'] = product.flavour + d2[product.desc]['packet_size'] = product.packet_size + self.products.setdefault(product.stock_code, {}).update(d2) + else: + self.products.setdefault(product.stock_code, {}).update(d2) + + def display_vending_machine(self): + for i,v in self.products.items(): + print(i, v) + + def choose_product(self, product): + product_name = product.stock_code + product_count = product.available + print("$"*100) + print(f"You have chosen {product_name} {product.desc}") + if product_count != 0: + print(f"feed in atleast {product.price} or more: ") + money = float(input()) + if money > product.price: + balance = money - product.price + print(f"Here is the balance : {balance}") + product.available -= 1 + elif money == product.price: + print("Perfect Change - Thank you") + product.available -= 1 + else: + print("Feed in more cash/coin") + print("$"*100) + print("Thank you for choosing this vending machine") + print("$"*100) + + +print('****************************************************************') + +final_product_set = () +ca_1 = Canned('Can', 'Coke', 5.00, 500, 5) +ca_2 = Canned('Can', 'Pepsi', 4.00, 250, 4) +ch_1 = Chips('Chips', 'Potato', 10.00, 100, 'salt', 2) +ch_2 = Chips('Chips', 'Tapioco', 10.00, 100, 'chilly', 3) +chl_1 = Chocolate('Chocolate', 'Kitkat', 1.00, 15) +chl_2 = Chocolate('Chocolate', 'Hersheys', 2.00, 20) +print("Total number of products available: ",Stock.counter) +print("products = ", Stock.stock_set) +vm = Vending_Machine() +vm.stock_details(ca_1) +vm.stock_details(ca_2) +vm.stock_details(ch_1) +vm.stock_details(ch_2) +vm.stock_details(chl_1) +vm.stock_details(chl_2) +vm.display_vending_machine() +vm.choose_product(ch_1) +vm.stock_details(ch_1) +vm.display_vending_machine() + From e15d3020e5d02679ffa2123f84234b1b8ba59ee0 Mon Sep 17 00:00:00 2001 From: bharani1990 Date: Sun, 3 Apr 2022 19:13:31 +0530 Subject: [PATCH 3/5] Delete Bharani_Flask_blog directory --- .../__pycache__/flaskblog.cpython-310.pyc | Bin 1214 -> 0 bytes .../__pycache__/forms.cpython-310.pyc | Bin 612 -> 0 bytes Bharani_Flask_blog/flaskblog.py | 51 ----------- Bharani_Flask_blog/forms.py | 9 -- Bharani_Flask_blog/static/main.css | 80 ------------------ Bharani_Flask_blog/templates/home.html | 10 --- Bharani_Flask_blog/templates/layout.html | 58 ------------- .../templates/post_creation.html | 40 --------- Bharani_Flask_blog/templates/posts.html | 15 ---- 9 files changed, 263 deletions(-) delete mode 100644 Bharani_Flask_blog/__pycache__/flaskblog.cpython-310.pyc delete mode 100644 Bharani_Flask_blog/__pycache__/forms.cpython-310.pyc delete mode 100644 Bharani_Flask_blog/flaskblog.py delete mode 100644 Bharani_Flask_blog/forms.py delete mode 100644 Bharani_Flask_blog/static/main.css delete mode 100644 Bharani_Flask_blog/templates/home.html delete mode 100644 Bharani_Flask_blog/templates/layout.html delete mode 100644 Bharani_Flask_blog/templates/post_creation.html delete mode 100644 Bharani_Flask_blog/templates/posts.html diff --git a/Bharani_Flask_blog/__pycache__/flaskblog.cpython-310.pyc b/Bharani_Flask_blog/__pycache__/flaskblog.cpython-310.pyc deleted file mode 100644 index 41e85e5524aa90073ff057a2fae5cea12524091c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1214 zcmZ{kOK;RL5P;)6cC*`k_5A=Oi`z=jRz+M8LVcjBNL5wQR!GrGQFiU_hE3v?Yy$PJ=}qwRhYG7)kbJCO5LRRLcg7ikebwC70NW&+LYr61Ez@9`VY9iV&P!~r zZ^}bne%)a6Y~h>$&*DMen@eAT*l1eX*^Yv=uj`U0j7wkfcn}4O>tZG&|5(VTts5_S zH%yfbR49^dA!A+I72R;8P96;y_-}MNB1=@h>h6nlq!l-NfeeyRyW2vjb`V9whp&1( zp{HRK(eWZZ4OFK`0~&=VoF0!IX^hrkWn&=2h^{_*K-boQr4VGQC!}^%s3M^3h(z&3 z=?R4J2auRE?d)-&)y{61WN(H$yJ4TFR0*0TVUjAKfMlma_QRx0Pq<9sSX3NCesHHj z!l**Vw&X#dh6-R+k0$)|8fFb)uE@&JS?P(Gcd(Q--LD=}#0 zx94w0qT3pu#9wP2#paNSV{Y6s z=H3VOlH|ZJaNwmXwJL~Q>C$*E8Q6l*0fLI(| z|5IG}I^tB~WlQ`K$RY|CogiWo#N79_6$}RXRcc3yO!2(>c@;*vEtw^^61z`h!Lo=y mBM>lM1u-|AH9qsSpj=j5q1o=m$v8S%7gGq zxpLwW;KVqo%38{3{xhDL-&nEJ>6qYoo*!MDP(mJ~*gPqU@A&y>B#~4TLxIxhCps|< zm`Ncu9C#mNIx{)slpGM5N`6NqS9Hywkl7h2^C#>=O4^NPy7pHy>rBbIcW1#h?Q+&A zEm5p4OcMq%Jy(Ci52xy0V%=oF4)v+JSv5|{%h+u5{D=LFQAL1C0*PXhs&q}3R3`Tc zaFt26p>tKpbWLF-IRa)~F}FTMFyQA+(5j>`zO8j5>tLOSe9yK)wV_Mnz2kD+6+*PN zQ9^WMA&iwP9sP+AH>+9?8OM;vWoSAcVpGSXpI;8WT;zt#_lrLe_dec^=H=twm+F^S z&R2)?YG3)QV6UtG>BLWMm(?w%8rzCb)dGqA?)6`nV_lr&3p54UqFZ!A`{;2wg3%(r zyZ9XzF2OwH=*7x`Fmm*0u>CK-`?h+|-#2;#9J~)$))ile-M`^qGz_1R9UQ&GUI9uy Bm23b2 diff --git a/Bharani_Flask_blog/flaskblog.py b/Bharani_Flask_blog/flaskblog.py deleted file mode 100644 index 5d53c24..0000000 --- a/Bharani_Flask_blog/flaskblog.py +++ /dev/null @@ -1,51 +0,0 @@ -from flask import Flask, render_template, url_for, flash, redirect -from forms import PostForm -from datetime import datetime - -app = Flask(__name__) -app.config['SECRET_KEY'] = '5791628bb0b13ce0c676dfde280ba245' -date = datetime.now() -blogposts = [ - { - 'author': 'Bharani', - 'title': 'Football', - 'content': 'When will Bharani watch a live football match', - 'date_posted': date.strftime("%d/%m/%y") - }, - { - 'author': 'Netra', - 'title': 'Linux', - 'content': 'Likes to uninstall a working version of linux and then break it with new', - 'date_posted': date.strftime("%d/%m/%y") - }, - { - 'author': 'Brinda', - 'title': 'Food In India', - 'content': 'Likes to try out new dish', - 'date_posted': date.strftime("%d/%m/%y") - } -] - - -@app.route("/") -@app.route("/home") -def home(): - return render_template('home.html', posts=blogposts, title='Home') - - -@app.route("/post") -def posts(): - return render_template('posts.html', posts=blogposts, title='Posts') - - -@app.route("/post_creation", methods=['GET', 'POST']) -def post_creation(): - form = PostForm() - if form.validate_on_submit(): - flash('Your post is done') - return redirect(url_for('home')) - return render_template('post_creation.html', title='Post Creation', form=form, posts=posts) - - -if __name__ == '__main__': - app.run(debug=True) diff --git a/Bharani_Flask_blog/forms.py b/Bharani_Flask_blog/forms.py deleted file mode 100644 index a024d77..0000000 --- a/Bharani_Flask_blog/forms.py +++ /dev/null @@ -1,9 +0,0 @@ -from flask_wtf import FlaskForm -from wtforms import StringField, SubmitField, TextAreaField -from wtforms.validators import DataRequired - - -class PostForm(FlaskForm): - title = StringField('Title', validators=[DataRequired()]) - content = TextAreaField('Content', validators=[DataRequired()]) - submit = SubmitField('Post') diff --git a/Bharani_Flask_blog/static/main.css b/Bharani_Flask_blog/static/main.css deleted file mode 100644 index a0ef716..0000000 --- a/Bharani_Flask_blog/static/main.css +++ /dev/null @@ -1,80 +0,0 @@ -body { - background: #fafafa; - color: #333333; - margin-top: 5rem; -} - -h1, h2, h3, h4, h5, h6 { - color: #444444; -} - -.bg-steel { - background-color: #800000; -} - -.site-header .navbar-nav .nav-link { - color: #ffa500; -} - -.site-header .navbar-nav .nav-link:hover { - color: #ffffff; -} - -.site-header .navbar-nav .nav-link.active { - font-weight: 500; -} - -.content-section { - background: #deb887; - padding: 10px 20px; - border: 1px solid #dddddd; - border-radius: 3px; - margin-bottom: 20px; -} - -.article-title { - color: #444444; -} - -a.article-title:hover { - color: #000000; - text-decoration: none; -} - -.article-content { - white-space: pre-line; -} - -.article-img { - height: 65px; - width: 65px; - margin-right: 16px; -} - -.article-metadata { - padding-bottom: 1px; - margin-bottom: 4px; - border-bottom: 1px solid #e3e3e3 -} - -.article-metadata a:hover { - color: #333; - text-decoration: none; -} - -.article-svg { - width: 25px; - height: 25px; - vertical-align: middle; -} - -.account-img { - height: 125px; - width: 125px; - margin-right: 20px; - margin-bottom: 16px; -} - -.account-heading { - font-size: 2.5rem; -} \ No newline at end of file diff --git a/Bharani_Flask_blog/templates/home.html b/Bharani_Flask_blog/templates/home.html deleted file mode 100644 index 0e769e4..0000000 --- a/Bharani_Flask_blog/templates/home.html +++ /dev/null @@ -1,10 +0,0 @@ -{% extends "layout.html" %} -{% block content %} - {% for post in posts %} - - {% endfor %} -{% endblock content %} diff --git a/Bharani_Flask_blog/templates/layout.html b/Bharani_Flask_blog/templates/layout.html deleted file mode 100644 index 1f4c9d0..0000000 --- a/Bharani_Flask_blog/templates/layout.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - {% if title %} - Flask Blog - {{ title }} - {% else %} - Flask Blog - {% endif %} - - - -
-
-
- {% block content %}{% endblock %} -
- - - - - - \ No newline at end of file diff --git a/Bharani_Flask_blog/templates/post_creation.html b/Bharani_Flask_blog/templates/post_creation.html deleted file mode 100644 index bc265ae..0000000 --- a/Bharani_Flask_blog/templates/post_creation.html +++ /dev/null @@ -1,40 +0,0 @@ -{% extends "layout.html" %} -{% block content %} -
-
- {{ form.hidden_tag() }} -
- Create a new Post -
- {{ form.title.label(class="form-control-label") }} - {% if form.title.errors %} - {{ form.title(class="form-control form-control-lg is-invalid") }} -
- {% for error in form.title.errors %} - {{ error }} - {% endfor %} -
- {% else %} - {{ form.title(class="form-control form-control-lg") }} - {% endif %} -
-
- {{ form.content.label(class="form-control-label") }} - {% if form.content.errors %} - {{ form.content(class="form-control form-control-lg is-invalid") }} -
- {% for error in form.content.errors %} - {{ error }} - {% endfor %} -
- {% else %} - {{ form.content(class="form-control form-control-lg") }} - {% endif %} -
-
-
- {{ form.submit(class="btn btn-outline-info") }} -
-
-
-{% endblock content %} \ No newline at end of file diff --git a/Bharani_Flask_blog/templates/posts.html b/Bharani_Flask_blog/templates/posts.html deleted file mode 100644 index 0cceb7f..0000000 --- a/Bharani_Flask_blog/templates/posts.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends "layout.html" %} -{% block content %} - {% for p in posts %} - - {% endfor %} -{% endblock content %} From 1bea214510def53250ac623c834e180d4623a473 Mon Sep 17 00:00:00 2001 From: bharani1990 Date: Sun, 3 Apr 2022 19:13:39 +0530 Subject: [PATCH 4/5] Delete Bharani_Vending_Machine directory --- Bharani_Vending_Machine/stock.py | 134 ------------------------------- 1 file changed, 134 deletions(-) delete mode 100644 Bharani_Vending_Machine/stock.py diff --git a/Bharani_Vending_Machine/stock.py b/Bharani_Vending_Machine/stock.py deleted file mode 100644 index 2d0695a..0000000 --- a/Bharani_Vending_Machine/stock.py +++ /dev/null @@ -1,134 +0,0 @@ -class Stock: - counter = 0 - stock_set = set() - def __init__(self, stock_code, desc, price, available): - self.stock_code = stock_code - self.desc = desc - self.price = price - self.available = available - Stock.counter += 1 - Stock.stock_set.add(self.desc) - - def sell_price(self): - sp = round(self.price, 2) - print('cost = $', sp) - - def label(self): - print(f"{self.desc} costs you {self.price}") - - def sale(self, discount): - new_sp = round(self.price * (1 - discount), 2) - print('the discounted price of {} is $ {}'.format((self.stock_code, self.desc), new_sp)) - return new_sp - -class Chocolate(Stock): - category = 'chocolate' - def __init__(self, stock_code, desc, price, available): - super().__init__(stock_code, desc, price, available) - - def __repr__(self): - print("You have chosen = {self.label}") - - -class Chips(Stock): - category = 'chips' - - def __init__(self, stock_code, desc, price, packet_size, flavour, available): - Stock.__init__(self, stock_code, desc, price, available) - self.packet_size = packet_size - self.flavour = flavour - - def __repr__(self): - print("You have chosen = {self.label}") - - def one_for_one(self): - # buy one get one offer - sp = round(self.price, 2) - print('Buy two packets of {} and get one free. You pay {}'.format(self.packet_size, sp)) - - -class Canned(Stock): - category = 'cans' - - def __init__(self, stock_code, desc, price, volume, available): - Stock.__init__(self, stock_code, desc, price, available) - self.volume = volume - - def label(self): - print(f'{self.desc}') - self.sell_price() - - def apply_discount(self, discount): - new_sp = self.sale(discount) - print('Price reduced ! you save = $ ', self.price - new_sp) - - -class Vending_Machine: - def __init__(self): - self.money = 0 - self.products = {} - - def stock_details(self, product): - d2 = {} - d2[product.desc] = {} - d2[product.desc]['price'] = product.price - d2[product.desc]['quantity'] = product.available - if product.stock_code == 'Can': - d2[product.desc]['volume'] = product.volume - self.products.setdefault(product.stock_code, {}).update(d2) - elif product.stock_code == 'Chips': - d2[product.desc]['flavour'] = product.flavour - d2[product.desc]['packet_size'] = product.packet_size - self.products.setdefault(product.stock_code, {}).update(d2) - else: - self.products.setdefault(product.stock_code, {}).update(d2) - - def display_vending_machine(self): - for i,v in self.products.items(): - print(i, v) - - def choose_product(self, product): - product_name = product.stock_code - product_count = product.available - print("$"*100) - print(f"You have chosen {product_name} {product.desc}") - if product_count != 0: - print(f"feed in atleast {product.price} or more: ") - money = float(input()) - if money > product.price: - balance = money - product.price - print(f"Here is the balance : {balance}") - product.available -= 1 - elif money == product.price: - print("Perfect Change - Thank you") - product.available -= 1 - else: - print("Feed in more cash/coin") - print("$"*100) - print("Thank you for choosing this vending machine") - print("$"*100) - - -print('****************************************************************') - -final_product_set = () -ca_1 = Canned('Can', 'Coke', 5.00, 500, 5) -ca_2 = Canned('Can', 'Pepsi', 4.00, 250, 4) -ch_1 = Chips('Chips', 'Potato', 10.00, 100, 'salt', 2) -ch_2 = Chips('Chips', 'Tapioco', 10.00, 100, 'chilly', 3) -chl_1 = Chocolate('Chocolate', 'Kitkat', 1.00, 15) -chl_2 = Chocolate('Chocolate', 'Hersheys', 2.00, 20) -print("Total number of products available: ",Stock.counter) -print("products = ", Stock.stock_set) -vm = Vending_Machine() -vm.stock_details(ca_1) -vm.stock_details(ca_2) -vm.stock_details(ch_1) -vm.stock_details(ch_2) -vm.stock_details(chl_1) -vm.stock_details(chl_2) -vm.display_vending_machine() -vm.choose_product(ch_1) -vm.stock_details(ch_1) -vm.display_vending_machine() - From e23a381ace06384cf346a964b469373182cb1e66 Mon Sep 17 00:00:00 2001 From: Bharani Date: Sun, 8 May 2022 20:17:09 +0530 Subject: [PATCH 5/5] hw_6 added --- hw_6/hw_6_stock_SOLID.ipynb | 1205 +++++++++++++++++++++++++++++++++++ hw_6/stock.py | 138 ++++ 2 files changed, 1343 insertions(+) create mode 100644 hw_6/hw_6_stock_SOLID.ipynb create mode 100644 hw_6/stock.py diff --git a/hw_6/hw_6_stock_SOLID.ipynb b/hw_6/hw_6_stock_SOLID.ipynb new file mode 100644 index 0000000..a5fd91b --- /dev/null +++ b/hw_6/hw_6_stock_SOLID.ipynb @@ -0,0 +1,1205 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 95, + "id": "1feb8d79-cb18-4be4-a2e4-4c3c7c4d762d", + "metadata": {}, + "outputs": [], + "source": [ + "# S" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "8570e64b-68d2-4737-9945-7ff0f3a53379", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "****************************************************************\n", + "Total number of products available: 6\n", + "products = {'Kitkat', 'Potato', 'Pepsi', 'Coke', 'Tapioco', 'Hersheys'}\n", + "Can {'Coke': {'price': 5.0, 'quantity': 5, 'volume': 500}, 'Pepsi': {'price': 4.0, 'quantity': 4, 'volume': 250}}\n", + "Chips {'Potato': {'price': 10.0, 'quantity': 2, 'flavour': 'salt', 'packet_size': 100}, 'Tapioco': {'price': 10.0, 'quantity': 3, 'flavour': 'chilly', 'packet_size': 100}}\n", + "Chocolate {'Kitkat': {'price': 1.0, 'quantity': 15}, 'Hersheys': {'price': 2.0, 'quantity': 20}}\n", + "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", + "You have chosen Chocolate Kitkat\n", + "feed in atleast 1.0 or more: \n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + " 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Here is the balance : 1.0\n", + "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", + "Thank you for choosing this vending machine\n", + "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", + "Can {'Coke': {'price': 5.0, 'quantity': 5, 'volume': 500}, 'Pepsi': {'price': 4.0, 'quantity': 4, 'volume': 250}}\n", + "Chips {'Potato': {'price': 10.0, 'quantity': 2, 'flavour': 'salt', 'packet_size': 100}, 'Tapioco': {'price': 10.0, 'quantity': 3, 'flavour': 'chilly', 'packet_size': 100}}\n", + "Chocolate {'Kitkat': {'price': 1.0, 'quantity': 14}, 'Hersheys': {'price': 2.0, 'quantity': 20}}\n" + ] + } + ], + "source": [ + "class Stock:\n", + " counter = 0\n", + " stock_set = set()\n", + "\n", + " def __init__(self, stock_code, desc, price, available):\n", + " self.stock_code = stock_code\n", + " self.desc = desc\n", + " self.price = price\n", + " self.available = available\n", + " Stock.counter += 1\n", + " Stock.stock_set.add(self.desc)\n", + "\n", + " def sell_price(self):\n", + " sp = round(self.price, 2)\n", + " print('cost = $', sp)\n", + "\n", + " def label(self):\n", + " print(f\"{self.desc} costs you {self.price}\")\n", + "\n", + " def sale(self, discount):\n", + " new_sp = round(self.price * (1 - discount), 2)\n", + " print('the discounted price of {} is $ {}'.format((self.stock_code, self.desc), new_sp))\n", + " return new_sp\n", + "\n", + "\n", + "class Chocolate(Stock):\n", + "\n", + " category = 'chocolate'\n", + "\n", + " def __init__(self, stock_code, desc, price, available):\n", + " super().__init__(stock_code, desc, price, available)\n", + "\n", + " def __repr__(self):\n", + " print(\"You have chosen = {self.label}\")\n", + "\n", + "\n", + "class Chips(Stock):\n", + " category = 'chips'\n", + "\n", + " def __init__(self, stock_code, desc, price, packet_size, flavour, available):\n", + " Stock.__init__(self, stock_code, desc, price, available)\n", + " self.packet_size = packet_size\n", + " self.flavour = flavour\n", + "\n", + " def __repr__(self):\n", + " print(\"You have chosen = {self.label}\")\n", + "\n", + " def one_for_one(self):\n", + " # buy one get one offer\n", + " sp = round(self.price, 2)\n", + " print('Buy two packets of {} and get one free. You pay {}'.format(self.packet_size, sp))\n", + "\n", + "\n", + "class Canned(Stock):\n", + " category = 'cans'\n", + "\n", + " def __init__(self, stock_code, desc, price, volume, available):\n", + " Stock.__init__(self, stock_code, desc, price, available)\n", + " self.volume = volume\n", + "\n", + " def label(self):\n", + " print(f'{self.desc}')\n", + " self.sell_price()\n", + "\n", + " def apply_discount(self, discount):\n", + " new_sp = self.sale(discount)\n", + " print('Price reduced ! you save = $ ', self.price - new_sp)\n", + "\n", + "\n", + "def choose_product(product):\n", + " product_name = product.stock_code\n", + " product_count = product.available\n", + " print(\"$\"*100)\n", + " print(f\"You have chosen {product_name} {product.desc}\")\n", + " if product_count != 0:\n", + " print(f\"feed in atleast {product.price} or more: \")\n", + " money = float(input())\n", + " if money > product.price:\n", + " balance = money - product.price\n", + " print(f\"Here is the balance : {balance}\")\n", + " product.available -= 1\n", + " elif money == product.price:\n", + " print(\"Perfect Change - Thank you\")\n", + " product.available -= 1\n", + " else:\n", + " print(\"Feed in more cash/coin\")\n", + " print(\"$\"*100)\n", + " print(\"Thank you for choosing this vending machine\")\n", + " print(\"$\"*100)\n", + "\n", + "\n", + "class VendingMachine:\n", + " def __init__(self):\n", + " self.money = 0\n", + " self.products = {} \n", + " \n", + "\n", + "\n", + "class Stock_Manipulation(VendingMachine):\n", + " \n", + " \n", + " def stock_details_can(self, product):\n", + " d2 = {product.desc: {}}\n", + " d2[product.desc]['price'] = product.price\n", + " d2[product.desc]['quantity'] = product.available\n", + " d2[product.desc]['volume'] = product.volume\n", + " self.products.setdefault(product.stock_code, {}).update(d2)\n", + " \n", + " def stock_details_chips(self, product):\n", + " d2 = {product.desc: {}}\n", + " d2[product.desc]['price'] = product.price\n", + " d2[product.desc]['quantity'] = product.available\n", + " d2[product.desc]['flavour'] = product.flavour\n", + " d2[product.desc]['packet_size'] = product.packet_size\n", + " self.products.setdefault(product.stock_code, {}).update(d2)\n", + "\n", + "\n", + " def stock_details_chocolates(self, product):\n", + " d2 = {product.desc: {}}\n", + " d2[product.desc]['price'] = product.price\n", + " d2[product.desc]['quantity'] = product.available\n", + " self.products.setdefault(product.stock_code, {}).update(d2)\n", + " \n", + " def display_vending_machine(self):\n", + " for i, v in self.products.items():\n", + " print(i, v)\n", + "\n", + "\n", + "\n", + "print('****************************************************************')\n", + "ca_1 = Canned('Can', 'Coke', 5.00, 500, 5)\n", + "ca_2 = Canned('Can', 'Pepsi', 4.00, 250, 4)\n", + "ch_1 = Chips('Chips', 'Potato', 10.00, 100, 'salt', 2)\n", + "ch_2 = Chips('Chips', 'Tapioco', 10.00, 100, 'chilly', 3)\n", + "chl_1 = Chocolate('Chocolate', 'Kitkat', 1.00, 15)\n", + "chl_2 = Chocolate('Chocolate', 'Hersheys', 2.00, 20)\n", + "print(\"Total number of products available: \",Stock.counter)\n", + "print(\"products = \", Stock.stock_set)\n", + "vm = VendingMachine()\n", + "sd = Stock_Manipulation()\n", + "sd.stock_details_can(ca_1)\n", + "sd.stock_details_can(ca_2)\n", + "sd.stock_details_chips(ch_1)\n", + "sd.stock_details_chips(ch_2)\n", + "sd.stock_details_chocolates(chl_1)\n", + "sd.stock_details_chocolates(chl_2)\n", + "sd.display_vending_machine()\n", + "choose_product(chl_1)\n", + "sd.stock_details_chocolates(chl_1)\n", + "sd.display_vending_machine()" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "id": "eb5d1d6c-063d-485c-b5ff-183ce347327f", + "metadata": {}, + "outputs": [], + "source": [ + "# O" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "5bc637a3-bad7-4bc5-b8ce-6ea14b49d58c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "****************************************************************\n", + "Total number of products available: 6\n", + "products = {'Kitkat', 'Potato', 'Pepsi', 'Coke', 'Tapioco', 'Hersheys'}\n", + "Can {'Coke': {'price': 5.0, 'quantity': 5, 'volume': 500}, 'Pepsi': {'price': 4.0, 'quantity': 4, 'volume': 250}}\n", + "Chips {'Potato': {'price': 10.0, 'quantity': 2, 'flavour': 'salt', 'packet_size': 100}, 'Tapioco': {'price': 10.0, 'quantity': 3, 'flavour': 'chilly', 'packet_size': 100}}\n", + "Chocolate {'Kitkat': {'price': 1.0, 'quantity': 15}, 'Hersheys': {'price': 2.0, 'quantity': 20}}\n", + "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", + "You have chosen Chips Tapioco\n", + "feed in atleast 10.0 or more: \n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + " 56\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Here is the balance : 46.0\n", + "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", + "Thank you for choosing this vending machine\n", + "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", + "Can {'Coke': {'price': 5.0, 'quantity': 5, 'volume': 500}, 'Pepsi': {'price': 4.0, 'quantity': 4, 'volume': 250}}\n", + "Chips {'Potato': {'price': 10.0, 'quantity': 2, 'flavour': 'salt', 'packet_size': 100}, 'Tapioco': {'price': 10.0, 'quantity': 2, 'flavour': 'chilly', 'packet_size': 100}}\n", + "Chocolate {'Kitkat': {'price': 1.0, 'quantity': 15}, 'Hersheys': {'price': 2.0, 'quantity': 20}}\n" + ] + } + ], + "source": [ + "from abc import ABC, abstractmethod\n", + "\n", + "class Stock:\n", + " counter = 0\n", + " stock_set = set()\n", + "\n", + " def __init__(self, stock_code, desc, price, available):\n", + " self.stock_code = stock_code\n", + " self.desc = desc\n", + " self.price = price\n", + " self.available = available\n", + " Stock.counter += 1\n", + " Stock.stock_set.add(self.desc)\n", + "\n", + " def sell_price(self):\n", + " sp = round(self.price, 2)\n", + " print('cost = $', sp)\n", + "\n", + " def label(self):\n", + " print(f\"{self.desc} costs you {self.price}\")\n", + "\n", + " def sale(self, discount):\n", + " new_sp = round(self.price * (1 - discount), 2)\n", + " print('the discounted price of {} is $ {}'.format((self.stock_code, self.desc), new_sp))\n", + " return new_sp\n", + "\n", + "\n", + "class Chocolate(Stock):\n", + "\n", + " category = 'chocolate'\n", + "\n", + " def __init__(self, stock_code, desc, price, available):\n", + " super().__init__(stock_code, desc, price, available)\n", + "\n", + " def __repr__(self):\n", + " print(\"You have chosen = {self.label}\")\n", + "\n", + "\n", + "class Chips(Stock):\n", + " category = 'chips'\n", + "\n", + " def __init__(self, stock_code, desc, price, packet_size, flavour, available):\n", + " Stock.__init__(self, stock_code, desc, price, available)\n", + " self.packet_size = packet_size\n", + " self.flavour = flavour\n", + "\n", + " def __repr__(self):\n", + " print(\"You have chosen = {self.label}\")\n", + "\n", + " def one_for_one(self):\n", + " # buy one get one offer\n", + " sp = round(self.price, 2)\n", + " print('Buy two packets of {} and get one free. You pay {}'.format(self.packet_size, sp))\n", + "\n", + "\n", + "class Canned(Stock):\n", + " category = 'cans'\n", + "\n", + " def __init__(self, stock_code, desc, price, volume, available):\n", + " Stock.__init__(self, stock_code, desc, price, available)\n", + " self.volume = volume\n", + "\n", + " def label(self):\n", + " print(f'{self.desc}')\n", + " self.sell_price()\n", + "\n", + " def apply_discount(self, discount):\n", + " new_sp = self.sale(discount)\n", + " print('Price reduced ! you save = $ ', self.price - new_sp)\n", + "\n", + "class VendingMachine:\n", + " \n", + " products = {}\n", + " \n", + " def __init__(self):\n", + " self.money = 0\n", + " \n", + " def display_vending_machine(self):\n", + " for k, v in self.products.items():\n", + " print(k, v)\n", + " \n", + "class StockManipulation(ABC):\n", + " \n", + " @abstractmethod\n", + " def update_stock(self, product):\n", + " pass\n", + "\n", + " \n", + "class StockDetailsCan(StockManipulation, VendingMachine):\n", + " def update_stock(self, product):\n", + " d2 = {product.desc: {}}\n", + " d2[product.desc]['price'] = product.price\n", + " d2[product.desc]['quantity'] = product.available\n", + " d2[product.desc]['volume'] = product.volume\n", + " self.products.setdefault(product.stock_code, {}).update(d2)\n", + "\n", + "class StockDetailsChips(StockManipulation, VendingMachine):\n", + " def update_stock(self, product):\n", + " d2 = {product.desc: {}}\n", + " d2[product.desc]['price'] = product.price\n", + " d2[product.desc]['quantity'] = product.available\n", + " d2[product.desc]['flavour'] = product.flavour\n", + " d2[product.desc]['packet_size'] = product.packet_size\n", + " self.products.setdefault(product.stock_code, {}).update(d2)\n", + "\n", + "class StockDetailsChocolate(StockManipulation, VendingMachine):\n", + " def update_stock(self, product):\n", + " d2 = {product.desc: {}}\n", + " d2[product.desc]['price'] = product.price\n", + " d2[product.desc]['quantity'] = product.available\n", + " self.products.setdefault(product.stock_code, {}).update(d2)\n", + "\n", + "\n", + "def choose_product(product):\n", + " product_name = product.stock_code\n", + " product_count = product.available\n", + " print(\"$\"*100)\n", + " print(f\"You have chosen {product_name} {product.desc}\")\n", + " if product_count != 0:\n", + " print(f\"feed in atleast {product.price} or more: \")\n", + " money = float(input())\n", + " if money > product.price:\n", + " balance = money - product.price\n", + " print(f\"Here is the balance : {balance}\")\n", + " product.available -= 1\n", + " elif money == product.price:\n", + " print(\"Perfect Change - Thank you\")\n", + " product.available -= 1\n", + " else:\n", + " print(\"Feed in more cash/coin\")\n", + " print(\"$\"*100)\n", + " print(\"Thank you for choosing this vending machine\")\n", + " print(\"$\"*100)\n", + "\n", + "print('****************************************************************')\n", + "\n", + "ca_1 = Canned('Can', 'Coke', 5.00, 500, 5)\n", + "ca_2 = Canned('Can', 'Pepsi', 4.00, 250, 4)\n", + "ch_1 = Chips('Chips', 'Potato', 10.00, 100, 'salt', 2)\n", + "ch_2 = Chips('Chips', 'Tapioco', 10.00, 100, 'chilly', 3)\n", + "chl_1 = Chocolate('Chocolate', 'Kitkat', 1.00, 15)\n", + "chl_2 = Chocolate('Chocolate', 'Hersheys', 2.00, 20)\n", + "print(\"Total number of products available: \",Stock.counter)\n", + "print(\"products = \", Stock.stock_set)\n", + "vm = VendingMachine()\n", + "can_obj = StockDetailsCan()\n", + "can_obj.update_stock(ca_1)\n", + "can_obj.update_stock(ca_2)\n", + "chips_obj = StockDetailsChips()\n", + "chips_obj.update_stock(ch_1)\n", + "chips_obj.update_stock(ch_2)\n", + "choco_obj = StockDetailsChocolate()\n", + "choco_obj.update_stock(chl_1)\n", + "choco_obj.update_stock(chl_2)\n", + "vm = VendingMachine()\n", + "vm.display_vending_machine()\n", + "choose_product(ch_2)\n", + "chips_obj.update_stock(ch_2)\n", + "vm.display_vending_machine()" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "f09b0a2b-3d47-480f-a3fd-e7a804dfdf69", + "metadata": {}, + "outputs": [], + "source": [ + "# L" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "30b86467-f52a-4bb2-8d20-e032c3752987", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "****************************************************************\n", + "Total number of products available: 6\n", + "products = {'Kitkat', 'Potato', 'Pepsi', 'Coke', 'Tapioco', 'Hersheys'}\n", + "Can {'Coke': {'price': 5.0, 'quantity': 500, 'volume': 5}, 'Pepsi': {'price': 4.0, 'quantity': 250, 'volume': 5}}\n", + "Chips {'Potato': {'price': 10.0, 'quantity': 100, 'flavour': 'salt', 'packet_size': 2}, 'Tapioco': {'price': 10.0, 'quantity': 100, 'flavour': 'salt', 'packet_size': 2}}\n", + "Chocolate {'Kitkat': {'price': 1.0, 'quantity': 15}, 'Hersheys': {'price': 2.0, 'quantity': 20}}\n", + "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", + "You have chosen Chips Tapioco\n", + "feed in atleast 10.0 or more: \n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + " 45\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Here is the balance : 35.0\n", + "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", + "Thank you for choosing this vending machine\n", + "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", + "Can {'Coke': {'price': 5.0, 'quantity': 500, 'volume': 5}, 'Pepsi': {'price': 4.0, 'quantity': 250, 'volume': 5}}\n", + "Chips {'Potato': {'price': 10.0, 'quantity': 100, 'flavour': 'salt', 'packet_size': 2}, 'Tapioco': {'price': 10.0, 'quantity': 99, 'flavour': 'salt', 'packet_size': 2}}\n", + "Chocolate {'Kitkat': {'price': 1.0, 'quantity': 15}, 'Hersheys': {'price': 2.0, 'quantity': 20}}\n" + ] + } + ], + "source": [ + "from abc import ABC, abstractmethod\n", + "\n", + "class Stock:\n", + " counter = 0\n", + " stock_set = set()\n", + "\n", + " def __init__(self, stock_code, desc, price, available):\n", + " self.stock_code = stock_code\n", + " self.desc = desc\n", + " self.price = price\n", + " self.available = available\n", + " Stock.counter += 1\n", + " Stock.stock_set.add(self.desc)\n", + "\n", + " def sell_price(self):\n", + " sp = round(self.price, 2)\n", + " print('cost = $', sp)\n", + "\n", + " def label(self):\n", + " print(f\"{self.desc} costs you {self.price}\")\n", + "\n", + " def sale(self, discount):\n", + " new_sp = round(self.price * (1 - discount), 2)\n", + " print('the discounted price of {} is $ {}'.format((self.stock_code, self.desc), new_sp))\n", + " return new_sp\n", + "\n", + "\n", + "class Chocolate(Stock):\n", + "\n", + " category = 'chocolate'\n", + "\n", + " def __init__(self, stock_code, desc, price, available):\n", + " super().__init__(stock_code, desc, price, available)\n", + "\n", + " def __repr__(self):\n", + " print(\"You have chosen = {self.label}\")\n", + "\n", + "\n", + "class Chips(Stock):\n", + " category = 'chips'\n", + "\n", + " def __init__(self, stock_code, desc, price, packet_size):\n", + " Stock.__init__(self, stock_code, desc, price, packet_size)\n", + "\n", + " def __repr__(self):\n", + " print(\"You have chosen = {self.label}\")\n", + "\n", + " def one_for_one(self):\n", + " # buy one get one offer\n", + " sp = round(self.price, 2)\n", + " print('Buy two packets of {} and get one free. You pay {}'.format(self.packet_size, sp))\n", + "\n", + "\n", + "class Canned(Stock):\n", + " category = 'cans'\n", + "\n", + " def __init__(self, stock_code, desc, price, available):\n", + " Stock.__init__(self, stock_code, desc, price, available)\n", + "\n", + " def label(self):\n", + " print(f'{self.desc}')\n", + " self.sell_price()\n", + "\n", + " def apply_discount(self, discount):\n", + " new_sp = self.sale(discount)\n", + " print('Price reduced ! you save = $ ', self.price - new_sp)\n", + "\n", + "class VendingMachine:\n", + " \n", + " products = {}\n", + " \n", + " def __init__(self):\n", + " self.money = 0\n", + " \n", + " def display_vending_machine(self):\n", + " for k, v in self.products.items():\n", + " print(k, v)\n", + "\n", + " \n", + "class StockManipulation(ABC):\n", + " \n", + " @abstractmethod\n", + " def update_stock(self, product):\n", + " pass\n", + "\n", + " \n", + "class StockDetailsCan(StockManipulation, VendingMachine):\n", + " \n", + " def __init__(self, volume):\n", + " self.volume = volume\n", + "\n", + " def update_stock(self, product):\n", + " d2 = {product.desc: {}}\n", + " d2[product.desc]['price'] = product.price\n", + " d2[product.desc]['quantity'] = product.available\n", + " d2[product.desc]['volume'] = self.volume \n", + " self.products.setdefault(product.stock_code, {}).update(d2)\n", + "\n", + "class StockDetailsChips(StockManipulation, VendingMachine):\n", + "\n", + " def __init__(self, flavour, packet_size):\n", + " self.flavour = flavour\n", + " self.packet_size = packet_size \n", + " \n", + " def update_stock(self, product):\n", + " d2 = {product.desc: {}}\n", + " d2[product.desc]['price'] = product.price\n", + " d2[product.desc]['quantity'] = product.available\n", + " d2[product.desc]['flavour'] = self.flavour\n", + " d2[product.desc]['packet_size'] = self.packet_size\n", + " self.products.setdefault(product.stock_code, {}).update(d2)\n", + "\n", + "class StockDetailsChocolate(StockManipulation, VendingMachine):\n", + "\n", + " \n", + " def update_stock(self, product):\n", + " d2 = {product.desc: {}}\n", + " d2[product.desc]['price'] = product.price\n", + " d2[product.desc]['quantity'] = product.available\n", + " self.products.setdefault(product.stock_code, {}).update(d2)\n", + "\n", + "\n", + "def choose_product(product):\n", + " product_name = product.stock_code\n", + " product_count = product.available\n", + " print(\"$\"*100)\n", + " print(f\"You have chosen {product_name} {product.desc}\")\n", + " if product_count != 0:\n", + " print(f\"feed in atleast {product.price} or more: \")\n", + " money = float(input())\n", + " if money > product.price:\n", + " balance = money - product.price\n", + " print(f\"Here is the balance : {balance}\")\n", + " product.available -= 1\n", + " elif money == product.price:\n", + " print(\"Perfect Change - Thank you\")\n", + " product.available -= 1\n", + " else:\n", + " print(\"Feed in more cash/coin\")\n", + " print(\"$\"*100)\n", + " print(\"Thank you for choosing this vending machine\")\n", + " print(\"$\"*100)\n", + "\n", + "print('****************************************************************')\n", + "\n", + "ca_1 = Canned('Can', 'Coke', 5.00, 500)\n", + "ca_2 = Canned('Can', 'Pepsi', 4.00, 250)\n", + "ch_1 = Chips('Chips', 'Potato', 10.00, 100)\n", + "ch_2 = Chips('Chips', 'Tapioco', 10.00, 100)\n", + "chl_1 = Chocolate('Chocolate', 'Kitkat', 1.00, 15)\n", + "chl_2 = Chocolate('Chocolate', 'Hersheys', 2.00, 20)\n", + "print(\"Total number of products available: \",Stock.counter)\n", + "print(\"products = \", Stock.stock_set)\n", + "vm = VendingMachine()\n", + "can_obj = StockDetailsCan(5)\n", + "can_obj.update_stock(ca_1)\n", + "can_obj.update_stock(ca_2)\n", + "chips_obj = StockDetailsChips('salt', 2)\n", + "chips_obj.update_stock(ch_1)\n", + "chips_obj.update_stock(ch_2)\n", + "choco_obj = StockDetailsChocolate()\n", + "choco_obj.update_stock(chl_1)\n", + "choco_obj.update_stock(chl_2)\n", + "vm = VendingMachine()\n", + "vm.display_vending_machine()\n", + "choose_product(ch_2)\n", + "chips_obj.update_stock(ch_2)\n", + "vm.display_vending_machine()" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "id": "361e3c97-b82e-4d83-b259-f01049f155b9", + "metadata": {}, + "outputs": [], + "source": [ + "# I" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "320cd653-3ef8-44b3-bb40-9157365e0bd7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "****************************************************************\n", + "Total number of products available: 6\n", + "products = {'Kitkat', 'Potato', 'Pepsi', 'Coke', 'Tapioco', 'Hersheys'}\n", + "product has volume = 5\n", + "product has volume = 5\n", + "product has flavour = salt and packet_size = 2\n", + "product has flavour = salt and packet_size = 2\n", + "Can {'Coke': {'price': 5.0, 'quantity': 500, 'volume': 5}, 'Pepsi': {'price': 4.0, 'quantity': 250, 'volume': 5}}\n", + "Chips {'Potato': {'price': 10.0, 'quantity': 100, 'flavour': 'salt', 'packet_size': 2}, 'Tapioco': {'price': 10.0, 'quantity': 100, 'flavour': 'salt', 'packet_size': 2}}\n", + "Chocolate {'Kitkat': {'price': 1.0, 'quantity': 15}, 'Hersheys': {'price': 2.0, 'quantity': 20}}\n", + "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", + "You have chosen Chocolate Hersheys\n", + "feed in atleast 2.0 or more: \n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + " 6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Here is the balance : 4.0\n", + "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", + "Thank you for choosing this vending machine\n", + "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", + "Can {'Coke': {'price': 5.0, 'quantity': 500, 'volume': 5}, 'Pepsi': {'price': 4.0, 'quantity': 250, 'volume': 5}}\n", + "Chips {'Potato': {'price': 10.0, 'quantity': 100, 'flavour': 'salt', 'packet_size': 2}, 'Tapioco': {'price': 10.0, 'quantity': 100, 'flavour': 'salt', 'packet_size': 2}}\n", + "Chocolate {'Kitkat': {'price': 1.0, 'quantity': 15}, 'Hersheys': {'price': 2.0, 'quantity': 19}}\n" + ] + } + ], + "source": [ + "from abc import ABC, abstractmethod\n", + "\n", + "class Stock:\n", + " counter = 0\n", + " stock_set = set()\n", + "\n", + " def __init__(self, stock_code, desc, price, available):\n", + " self.stock_code = stock_code\n", + " self.desc = desc\n", + " self.price = price\n", + " self.available = available\n", + " Stock.counter += 1\n", + " Stock.stock_set.add(self.desc)\n", + "\n", + " def sell_price(self):\n", + " sp = round(self.price, 2)\n", + " print('cost = $', sp)\n", + "\n", + " def label(self):\n", + " print(f\"{self.desc} costs you {self.price}\")\n", + "\n", + " def sale(self, discount):\n", + " new_sp = round(self.price * (1 - discount), 2)\n", + " print('the discounted price of {} is $ {}'.format((self.stock_code, self.desc), new_sp))\n", + " return new_sp\n", + "\n", + "\n", + "class Chocolate(Stock):\n", + "\n", + " category = 'chocolate'\n", + "\n", + " def __init__(self, stock_code, desc, price, available):\n", + " super().__init__(stock_code, desc, price, available)\n", + "\n", + " def __repr__(self):\n", + " print(\"You have chosen = {self.label}\")\n", + "\n", + "\n", + "class Chips(Stock):\n", + " category = 'chips'\n", + "\n", + " def __init__(self, stock_code, desc, price, packet_size):\n", + " Stock.__init__(self, stock_code, desc, price, packet_size)\n", + "\n", + " def __repr__(self):\n", + " print(\"You have chosen = {self.label}\")\n", + "\n", + " def one_for_one(self):\n", + " # buy one get one offer\n", + " sp = round(self.price, 2)\n", + " print('Buy two packets of {} and get one free. You pay {}'.format(self.packet_size, sp))\n", + "\n", + "\n", + "class Canned(Stock):\n", + " category = 'cans'\n", + "\n", + " def __init__(self, stock_code, desc, price, available):\n", + " Stock.__init__(self, stock_code, desc, price, available)\n", + "\n", + " def label(self):\n", + " print(f'{self.desc}')\n", + " self.sell_price()\n", + "\n", + " def apply_discount(self, discount):\n", + " new_sp = self.sale(discount)\n", + " print('Price reduced ! you save = $ ', self.price - new_sp)\n", + "\n", + "class VendingMachine:\n", + " \n", + " products = {}\n", + " \n", + " def __init__(self):\n", + " self.money = 0\n", + " \n", + " def display_vending_machine(self):\n", + " for k, v in self.products.items():\n", + " print(k, v)\n", + "\n", + " \n", + "class StockManipulation(ABC):\n", + " \n", + " @abstractmethod\n", + " def update_stock(self, product):\n", + " pass\n", + " \n", + " \n", + "class StockManipulation_Print(ABC):\n", + " \n", + " @abstractmethod\n", + " def update_stock(self, product):\n", + " pass\n", + " \n", + " @abstractmethod\n", + " def print_special_attribute(self, product):\n", + " pass\n", + "\n", + "\n", + " \n", + "class StockDetailsCan(StockManipulation_Print, VendingMachine):\n", + " \n", + " def __init__(self, volume):\n", + " self.volume = volume\n", + "\n", + "\n", + " def update_stock(self, product):\n", + " d2 = {product.desc: {}}\n", + " d2[product.desc]['price'] = product.price\n", + " d2[product.desc]['quantity'] = product.available\n", + " d2[product.desc]['volume'] = self.volume \n", + " self.products.setdefault(product.stock_code, {}).update(d2)\n", + " \n", + " def print_special_attribute(self):\n", + " print(\"product has volume = \", self.volume)\n", + "\n", + "class StockDetailsChips(StockManipulation_Print, VendingMachine):\n", + "\n", + " def __init__(self, flavour, packet_size):\n", + " self.flavour = flavour\n", + " self.packet_size = packet_size \n", + " \n", + " def update_stock(self, product):\n", + " d2 = {product.desc: {}}\n", + " d2[product.desc]['price'] = product.price\n", + " d2[product.desc]['quantity'] = product.available\n", + " d2[product.desc]['flavour'] = self.flavour\n", + " d2[product.desc]['packet_size'] = self.packet_size\n", + " self.products.setdefault(product.stock_code, {}).update(d2)\n", + " \n", + " def print_special_attribute(self):\n", + " print(f\"product has flavour = {self.flavour } and packet_size = {self.packet_size}\")\n", + "\n", + "class StockDetailsChocolate(StockManipulation, VendingMachine):\n", + "\n", + " \n", + " def update_stock(self, product):\n", + " d2 = {product.desc: {}}\n", + " d2[product.desc]['price'] = product.price\n", + " d2[product.desc]['quantity'] = product.available\n", + " self.products.setdefault(product.stock_code, {}).update(d2)\n", + "\n", + "\n", + "def choose_product(product):\n", + " product_name = product.stock_code\n", + " product_count = product.available\n", + " print(\"$\"*100)\n", + " print(f\"You have chosen {product_name} {product.desc}\")\n", + " if product_count != 0:\n", + " print(f\"feed in atleast {product.price} or more: \")\n", + " money = float(input())\n", + " if money > product.price:\n", + " balance = money - product.price\n", + " print(f\"Here is the balance : {balance}\")\n", + " product.available -= 1\n", + " elif money == product.price:\n", + " print(\"Perfect Change - Thank you\")\n", + " product.available -= 1\n", + " else:\n", + " print(\"Feed in more cash/coin\")\n", + " print(\"$\"*100)\n", + " print(\"Thank you for choosing this vending machine\")\n", + " print(\"$\"*100)\n", + "\n", + "print('****************************************************************')\n", + "\n", + "ca_1 = Canned('Can', 'Coke', 5.00, 500)\n", + "ca_2 = Canned('Can', 'Pepsi', 4.00, 250)\n", + "ch_1 = Chips('Chips', 'Potato', 10.00, 100)\n", + "ch_2 = Chips('Chips', 'Tapioco', 10.00, 100)\n", + "chl_1 = Chocolate('Chocolate', 'Kitkat', 1.00, 15)\n", + "chl_2 = Chocolate('Chocolate', 'Hersheys', 2.00, 20)\n", + "print(\"Total number of products available: \",Stock.counter)\n", + "print(\"products = \", Stock.stock_set)\n", + "vm = VendingMachine()\n", + "can_obj = StockDetailsCan(5)\n", + "can_obj.update_stock(ca_1)\n", + "can_obj.print_special_attribute()\n", + "can_obj.update_stock(ca_2)\n", + "can_obj.print_special_attribute()\n", + "chips_obj = StockDetailsChips('salt', 2)\n", + "chips_obj.update_stock(ch_1)\n", + "chips_obj.print_special_attribute()\n", + "chips_obj.update_stock(ch_2)\n", + "chips_obj.print_special_attribute()\n", + "choco_obj = StockDetailsChocolate()\n", + "choco_obj.update_stock(chl_1)\n", + "choco_obj.update_stock(chl_2)\n", + "vm = VendingMachine()\n", + "vm.display_vending_machine()\n", + "choose_product(chl_2)\n", + "choco_obj.update_stock(chl_2)\n", + "vm.display_vending_machine()" + ] + }, + { + "cell_type": "code", + "execution_count": 87, + "id": "9f20f53f-2a42-4ec7-9fa7-6c0b1203ea9d", + "metadata": {}, + "outputs": [], + "source": [ + "# D" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "d9882275-a2d2-4258-8990-7ac09dc3543c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "****************************************************************\n", + "Total number of products available: 6\n", + "products = {'Kitkat', 'Potato', 'Pepsi', 'Coke', 'Tapioco', 'Hersheys'}\n", + "product has volume = 5\n", + "product has volume = 5\n", + "product has flavour = salt and packet_size = 2\n", + "product has flavour = salt and packet_size = 2\n", + "Can {'Coke': {'price': 5.0, 'quantity': 500, 'volume': 5}, 'Pepsi': {'price': 4.0, 'quantity': 250, 'volume': 5}}\n", + "Chips {'Potato': {'price': 10.0, 'quantity': 100, 'flavour': 'salt', 'packet_size': 2}, 'Tapioco': {'price': 10.0, 'quantity': 100, 'flavour': 'salt', 'packet_size': 2}}\n", + "Chocolate {'Kitkat': {'price': 1.0, 'quantity': 15}, 'Hersheys': {'price': 2.0, 'quantity': 20}}\n", + "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", + "You have chosen Can Coke\n", + "feed in atleast 5.0 or more: \n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + " 6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "type of money = coin\n", + "Here is the balance : 1.0\n", + "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", + "Thank you for choosing this vending machine\n", + "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n", + "Can {'Coke': {'price': 5.0, 'quantity': 499, 'volume': 5}, 'Pepsi': {'price': 4.0, 'quantity': 250, 'volume': 5}}\n", + "Chips {'Potato': {'price': 10.0, 'quantity': 100, 'flavour': 'salt', 'packet_size': 2}, 'Tapioco': {'price': 10.0, 'quantity': 100, 'flavour': 'salt', 'packet_size': 2}}\n", + "Chocolate {'Kitkat': {'price': 1.0, 'quantity': 15}, 'Hersheys': {'price': 2.0, 'quantity': 20}}\n" + ] + } + ], + "source": [ + "from abc import ABC, abstractmethod\n", + "\n", + "class Stock:\n", + " counter = 0\n", + " stock_set = set()\n", + "\n", + " def __init__(self, stock_code, desc, price, available):\n", + " self.stock_code = stock_code\n", + " self.desc = desc\n", + " self.price = price\n", + " self.available = available\n", + " Stock.counter += 1\n", + " Stock.stock_set.add(self.desc)\n", + "\n", + " def sell_price(self):\n", + " sp = round(self.price, 2)\n", + " print('cost = $', sp)\n", + "\n", + " def label(self):\n", + " print(f\"{self.desc} costs you {self.price}\")\n", + "\n", + " def sale(self, discount):\n", + " new_sp = round(self.price * (1 - discount), 2)\n", + " print('the discounted price of {} is $ {}'.format((self.stock_code, self.desc), new_sp))\n", + " return new_sp\n", + "\n", + "\n", + "class Chocolate(Stock):\n", + "\n", + " category = 'chocolate'\n", + "\n", + " def __init__(self, stock_code, desc, price, available):\n", + " super().__init__(stock_code, desc, price, available)\n", + "\n", + " def __repr__(self):\n", + " print(\"You have chosen = {self.label}\")\n", + "\n", + "\n", + "class Chips(Stock):\n", + " category = 'chips'\n", + "\n", + " def __init__(self, stock_code, desc, price, packet_size):\n", + " Stock.__init__(self, stock_code, desc, price, packet_size)\n", + "\n", + " def __repr__(self):\n", + " print(\"You have chosen = {self.label}\")\n", + "\n", + " def one_for_one(self):\n", + " # buy one get one offer\n", + " sp = round(self.price, 2)\n", + " print('Buy two packets of {} and get one free. You pay {}'.format(self.packet_size, sp))\n", + "\n", + "\n", + "class Canned(Stock):\n", + " category = 'cans'\n", + "\n", + " def __init__(self, stock_code, desc, price, available):\n", + " Stock.__init__(self, stock_code, desc, price, available)\n", + "\n", + " def label(self):\n", + " print(f'{self.desc}')\n", + " self.sell_price()\n", + "\n", + " def apply_discount(self, discount):\n", + " new_sp = self.sale(discount)\n", + " print('Price reduced ! you save = $ ', self.price - new_sp)\n", + "\n", + "class VendingMachine:\n", + " \n", + " products = {}\n", + " money = 0\n", + " \n", + " def display_vending_machine(self):\n", + " for k, v in self.products.items():\n", + " print(k, v)\n", + "\n", + " \n", + "class StockManipulation(ABC):\n", + " \n", + " @abstractmethod\n", + " def update_stock(self, product):\n", + " pass\n", + " \n", + " \n", + "class StockManipulation_Print(ABC):\n", + " \n", + " @abstractmethod\n", + " def update_stock(self, product):\n", + " pass\n", + " \n", + " @abstractmethod\n", + " def print_special_attribute(self, product):\n", + " pass\n", + " \n", + "\n", + "class MoneyDependency(ABC):\n", + " \n", + " @abstractmethod\n", + " def do_you_have_enough_money(self):\n", + " pass\n", + " \n", + "\n", + "class CashMoney(MoneyDependency, VendingMachine):\n", + " \n", + " def do_you_have_enough_money(self):\n", + " return True\n", + " \n", + " def print_type_of_money(self):\n", + " print(\"type of money = cash\")\n", + "\n", + "class CoinMoney(MoneyDependency, VendingMachine): \n", + " \n", + " def do_you_have_enough_money(self):\n", + " return True\n", + " \n", + " def print_type_of_money(self):\n", + " print(\"type of money = coin\")\n", + "\n", + " \n", + "class StockDetailsCan(StockManipulation_Print, VendingMachine):\n", + " \n", + " def __init__(self, volume):\n", + " self.volume = volume\n", + "\n", + "\n", + " def update_stock(self, product):\n", + " d2 = {product.desc: {}}\n", + " d2[product.desc]['price'] = product.price\n", + " d2[product.desc]['quantity'] = product.available\n", + " d2[product.desc]['volume'] = self.volume \n", + " self.products.setdefault(product.stock_code, {}).update(d2)\n", + " \n", + " def print_special_attribute(self):\n", + " print(\"product has volume = \", self.volume)\n", + "\n", + "class StockDetailsChips(StockManipulation_Print, VendingMachine):\n", + "\n", + " def __init__(self, flavour, packet_size):\n", + " self.flavour = flavour\n", + " self.packet_size = packet_size \n", + " \n", + " def update_stock(self, product):\n", + " d2 = {product.desc: {}}\n", + " d2[product.desc]['price'] = product.price\n", + " d2[product.desc]['quantity'] = product.available\n", + " d2[product.desc]['flavour'] = self.flavour\n", + " d2[product.desc]['packet_size'] = self.packet_size\n", + " self.products.setdefault(product.stock_code, {}).update(d2)\n", + " \n", + " def print_special_attribute(self):\n", + " print(f\"product has flavour = {self.flavour } and packet_size = {self.packet_size}\")\n", + "\n", + "class StockDetailsChocolate(StockManipulation, VendingMachine):\n", + "\n", + " \n", + " def update_stock(self, product):\n", + " d2 = {product.desc: {}}\n", + " d2[product.desc]['price'] = product.price\n", + " d2[product.desc]['quantity'] = product.available\n", + " self.products.setdefault(product.stock_code, {}).update(d2)\n", + "\n", + "\n", + "def choose_product(product):\n", + " \n", + " product_name = product.stock_code\n", + " product_count = product.available\n", + " print(\"$\"*100)\n", + " print(f\"You have chosen {product_name} {product.desc}\")\n", + " if product_count != 0:\n", + " print(f\"feed in atleast {product.price} or more: \")\n", + " money = float(input())\n", + " cash_money = CashMoney()\n", + " coin_money = CoinMoney()\n", + " if money < 10:\n", + " coin_money.print_type_of_money()\n", + " else:\n", + " cash_money.print_type_of_money() \n", + " \n", + " if money > product.price:\n", + " balance = money - product.price\n", + " print(f\"Here is the balance : {balance}\")\n", + " product.available -= 1\n", + " elif money == product.price:\n", + " print(\"Perfect Change - Thank you\")\n", + " product.available -= 1\n", + " else:\n", + " print(\"Feed in more cash/coin\")\n", + " print(\"$\"*100)\n", + " print(\"Thank you for choosing this vending machine\")\n", + " print(\"$\"*100)\n", + "\n", + "print('****************************************************************')\n", + "\n", + "ca_1 = Canned('Can', 'Coke', 5.00, 500)\n", + "ca_2 = Canned('Can', 'Pepsi', 4.00, 250)\n", + "ch_1 = Chips('Chips', 'Potato', 10.00, 100)\n", + "ch_2 = Chips('Chips', 'Tapioco', 10.00, 100)\n", + "chl_1 = Chocolate('Chocolate', 'Kitkat', 1.00, 15)\n", + "chl_2 = Chocolate('Chocolate', 'Hersheys', 2.00, 20)\n", + "print(\"Total number of products available: \",Stock.counter)\n", + "print(\"products = \", Stock.stock_set)\n", + "vm = VendingMachine()\n", + "can_obj = StockDetailsCan(5)\n", + "can_obj.update_stock(ca_1)\n", + "can_obj.print_special_attribute()\n", + "can_obj.update_stock(ca_2)\n", + "can_obj.print_special_attribute()\n", + "chips_obj = StockDetailsChips('salt', 2)\n", + "chips_obj.update_stock(ch_1)\n", + "chips_obj.print_special_attribute()\n", + "chips_obj.update_stock(ch_2)\n", + "chips_obj.print_special_attribute()\n", + "choco_obj = StockDetailsChocolate()\n", + "choco_obj.update_stock(chl_1)\n", + "choco_obj.update_stock(chl_2)\n", + "vm = VendingMachine()\n", + "vm.display_vending_machine()\n", + "choose_product(ca_1)\n", + "can_obj.update_stock(ca_1)\n", + "vm.display_vending_machine()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b81ea01c-42e3-46d2-b228-99c5b9804387", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/hw_6/stock.py b/hw_6/stock.py new file mode 100644 index 0000000..7411fc7 --- /dev/null +++ b/hw_6/stock.py @@ -0,0 +1,138 @@ +class Stock: + counter = 0 + stock_set = set() + + def __init__(self, stock_code, desc, price, available): + self.stock_code = stock_code + self.desc = desc + self.price = price + self.available = available + Stock.counter += 1 + Stock.stock_set.add(self.desc) + + def sell_price(self): + sp = round(self.price, 2) + print('cost = $', sp) + + def label(self): + print(f"{self.desc} costs you {self.price}") + + def sale(self, discount): + new_sp = round(self.price * (1 - discount), 2) + print('the discounted price of {} is $ {}'.format((self.stock_code, self.desc), new_sp)) + return new_sp + + +class Chocolate(Stock): + + category = 'chocolate' + + def __init__(self, stock_code, desc, price, available): + super().__init__(stock_code, desc, price, available) + + def __repr__(self): + print("You have chosen = {self.label}") + + +class Chips(Stock): + category = 'chips' + + def __init__(self, stock_code, desc, price, packet_size, flavour, available): + Stock.__init__(self, stock_code, desc, price, available) + self.packet_size = packet_size + self.flavour = flavour + + def __repr__(self): + print("You have chosen = {self.label}") + + def one_for_one(self): + # buy one get one offer + sp = round(self.price, 2) + print('Buy two packets of {} and get one free. You pay {}'.format(self.packet_size, sp)) + + +class Canned(Stock): + category = 'cans' + + def __init__(self, stock_code, desc, price, volume, available): + Stock.__init__(self, stock_code, desc, price, available) + self.volume = volume + + def label(self): + print(f'{self.desc}') + self.sell_price() + + def apply_discount(self, discount): + new_sp = self.sale(discount) + print('Price reduced ! you save = $ ', self.price - new_sp) + + +def choose_product(product): + product_name = product.stock_code + product_count = product.available + print("$"*100) + print(f"You have chosen {product_name} {product.desc}") + if product_count != 0: + print(f"feed in atleast {product.price} or more: ") + money = float(input()) + if money > product.price: + balance = money - product.price + print(f"Here is the balance : {balance}") + product.available -= 1 + elif money == product.price: + print("Perfect Change - Thank you") + product.available -= 1 + else: + print("Feed in more cash/coin") + print("$"*100) + print("Thank you for choosing this vending machine") + print("$"*100) + + +class VendingMachine: + def __init__(self): + self.money = 0 + self.products = {} + + def stock_details(self, product): + d2 = {product.desc: {}} + d2[product.desc]['price'] = product.price + d2[product.desc]['quantity'] = product.available + if product.stock_code == 'Can': + d2[product.desc]['volume'] = product.volume + self.products.setdefault(product.stock_code, {}).update(d2) + elif product.stock_code == 'Chips': + d2[product.desc]['flavour'] = product.flavour + d2[product.desc]['packet_size'] = product.packet_size + self.products.setdefault(product.stock_code, {}).update(d2) + else: + self.products.setdefault(product.stock_code, {}).update(d2) + + def display_vending_machine(self): + for i, v in self.products.items(): + print(i, v) + + +print('****************************************************************') + +final_product_set = () +ca_1 = Canned('Can', 'Coke', 5.00, 500, 5) +ca_2 = Canned('Can', 'Pepsi', 4.00, 250, 4) +ch_1 = Chips('Chips', 'Potato', 10.00, 100, 'salt', 2) +ch_2 = Chips('Chips', 'Tapioco', 10.00, 100, 'chilly', 3) +chl_1 = Chocolate('Chocolate', 'Kitkat', 1.00, 15) +chl_2 = Chocolate('Chocolate', 'Hersheys', 2.00, 20) +print("Total number of products available: ",Stock.counter) +print("products = ", Stock.stock_set) +vm = VendingMachine() +vm.stock_details(ca_1) +vm.stock_details(ca_2) +vm.stock_details(ch_1) +vm.stock_details(ch_2) +vm.stock_details(chl_1) +vm.stock_details(chl_2) +vm.display_vending_machine() +choose_product(ch_1) +vm.stock_details(ch_1) +vm.display_vending_machine() +