Skip to content

Commit 43b57f0

Browse files
Add files via upload
1 parent ca9b155 commit 43b57f0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

python_study_2/page1/script.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
money = 20
2+
items = {'apple': 2, 'banana': 4, 'orange': 6}
3+
for item_name in items:
4+
print('--------------------------------------------------')
5+
print('You have ' + str(money) + ' dollars in your wallet')
6+
print('Each ' + item_name + ' costs ' + str(items[item_name]) + ' dollars')
7+
8+
input_count = input('How many ' + item_name + 's do you want?:')
9+
print('You will buy ' + input_count + ' ' + item_name + 's')
10+
11+
count = int(input_count)
12+
total_price = items[item_name] * count
13+
print('The total price is ' + str(total_price) + ' dollars')
14+
15+
if money >= total_price:
16+
print('You have bought ' + input_count + ' ' + item_name + 's')
17+
money -= total_price
18+
19+
if money == 0:
20+
print('Your wallet is now empty')
21+
break
22+
else:
23+
print('You do not have enough money')
24+
print('You cannot buy that many ' + item_name + 's')
25+
print('The balance is ' + str(money) + ' dollars')

0 commit comments

Comments
 (0)