Skip to content

Add exercise script - buy_nine_get_one_free.py #555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions buy_nine_get_one_free.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Buy 9 Get 1 Free

def buy_nine_get_one_free(my_quantity, my_product_price):
my_price_to_pay = 0
for my_q in range(1,my_quantity+1):
if my_q % 10 == 0:
my_price_to_pay = my_price_to_pay
else:
my_price_to_pay += my_product_price
return my_price_to_pay


# Asserts
assert buy_nine_get_one_free(8, 2.50) == 20
assert buy_nine_get_one_free(9, 2.50) == 22.50
assert buy_nine_get_one_free(10, 2.50) == 22.50
assert buy_nine_get_one_free(11, 2.50) == 25