8000 Added new Python exercises · codeguage-code/exercises@9ddc1b6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ddc1b6

Browse files
Added new Python exercises
1 parent 284501a commit 9ddc1b6

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Price After Discount Exercise
3+
4+
Read the exercise's description at [Python Strings — Price After Discount Exercise](https://www.codeguage.com/courses/python/strings-price-after-discount-exercise).
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
items = [(50, 30), (85, 10), (300, 15), (20, 5)]
2+
col_len = 20
3+
4+
print('Price'.ljust(col_len) + 'Discount'.ljust(col_len) + 'Price after discount'.ljust(col_len))
5+
print()
6+
7+
for item in items:
8+
price = item[0]
9+
discount = item[1]
10+
final_price = price - (price * discount / 100)
11+
12+
price = '${:.2f}'.format(price)
13+
final_price = '${:.2f}'.format(final_price)
14+
discount = str(discount) + '%'
15+
16+
print(price.ljust(col_len) + discount.ljust(col_len) + final_price.ljust(col_len))

0 commit comments

Comments
 (0)
0