product_list
=
[
(
'Iphone'
,
5800
),
(
'Mac Pro'
,
9800
),
(
'Bike'
,
800
),
(
'Watch'
,
10600
),
(
'Coffee'
,
31
),
(
'Lancy Python'
,
120
)
]
shopping_list
=
[]
salary
=
input
(
"请输入工资:"
)
if
salary.isdigit():
salary
=
int
(salary)
while
True
:
for
index,item
in
enumerate
(product_list):
print
(index,item)
user_choice
=
input
(
"是否购买商品?如果要购买商品请输入商品编号:"
)
if
user_choice.isdigit():
user_choice
=
int
(user_choice)
if
user_choice<
len
(product_list)
and
user_choice>
=
0
:
p_item
=
product_list[user_choice]
if
p_item[
1
]<
=
salary:
shopping_list.append(p_item)
salary
-
=
p_item[
1
]
print
(
"您购买的商品为%s,余额为\033[31;1m%s\033[0m"
%
(p_item,salary))
else
:
print
(
"\033[41;1m你的余额只剩[%s]\033[0m"
%
salary)
else
:
print
(
"该商品不存在!"
)
elif
user_choice
=
=
'q'
:
print
(
"--------以下是购买的商品--------"
)
for
p
in
shopping_list:
print
(p)
print
(
"您的余额为:"
,salary)
exit()
else
:
print
(
"该商品不存在!"
)