-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloops & conditionals
More file actions
28 lines (23 loc) · 1.12 KB
/
loops & conditionals
File metadata and controls
28 lines (23 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
money = 20
items = {'apple': 2, 'banana': 4, 'orange': 6}
for item_name in items:
print('--------------------------------------------------')
print('You have ' + str(money) + ' dollars in your wallet')
print('Each ' + item_name + ' costs ' + str(items[item_name]) + ' dollars')
input_count = input('How many ' + item_name + 's do you want?: ')
print('You will buy ' + input_count + ' ' + item_name + 's')
count = int(input_count)
total_price = items[item_name] * count
print('The total price is ' + str(total_price) + ' dollars')
if money >= total_price:
print('You have bought ' + input_count + ' ' + item_name + 's')
money -= total_price
# When money is equal to 0, print 'Your wallet is now empty' and stop the loop
if money == 0:
print('Your wallet is now empty')
break
else:
print('You do not have enough money')
print('You cannot buy that many ' + item_name + 's')
# Using the money variable and type conversion, print 'You have ____ dollars left'
print('You have ' + str(money) + ' dollars left')