The fifth day, the fourth day to review the contents of the shopping cart applet job. Tuple

#__author__: Zoe 
#date: 2019/5/31
salary = int (the INPUT ( "Welcome! Please enter your budget:"))
Print ( '1 iphone6s.', '\ t', '5800', ' \ n-'
' 2. MAC Book ',' \ T ',' 9000 ',' \ n-'
' 3. Coffee ',' \ T \ T ',' 32 ',' \ n-'
' Python 4. Book ' , '', '80', '\ n-'
'5. The Bicycle', '\ T \ T', '1500', End = '\ n-')
Goods = [ '0', 'ipone6s',' MAC Book ',' Coffee ',' Python Book ',' Bicycle ']
. price = [' 0 ',' 5800 ',' 9000 ',' 32 ',' 80 ',' 1500 ']
Shopping_cart = List ()
rest_cash = int (the salary)
quit_flag = True
the while quit_flag:
Choice = INPUT ( 'Please select or exit by q:')
IF Choice == 'q':
quit_flag = False
Continue
IF rest_cash - int ( price [int (choice)]) <0:
print ( 'insufficient funds, need to re-select.', - (rest_cash - int (. price [int (Choice)])))
Continue
rest_cash - = int (. price [int (Choice)])
shopping_cart.append (Goods [ int (Choice)])
Print (Goods [int (Choice)], 'has been added to your shopping cart, the current balance:', rest_cash)
the else:
Print ( 'Welcome to the next visit, you have purchased:', shopping_cart, ' total cost: ', salary - rest_cash)

tuples Like lists
a = (1,2,3,4,5)
can sliced values, a tuple can not modify the contents inside.

cart program can continue to optimize.

Guess you like

Origin www.cnblogs.com/zpzhou/p/10956472.html
Recommended