python 3.5 购物小程序

时间:2021-03-16 14:03:31
 #!/usr/bin/env python
#encoding: utf-8
import time
import os nowtime = time.strftime('%Y-%m-%d %H:%M:%S')
shopping_total_money = 0
shopping_car = {} def touch_shopping_log():
with open('shopping_log.txt', 'w') as shopping_log:
pass def shopping_log_add(log):
with open('shopping_log.txt', 'a') as shopping_log:
shopping_log.write('%s : %s : %s\n' % (nowtime,name,log)) shopping_list = [
["phone",100],
["computer",200],
["car",1000],
["home",10000],
]
def welcome_info(): print ('_________________________________')
print ('welcome to shopping 北京购物广场')
print ('now time is : %s' % (nowtime))
print ('_________________________________') def shopping_list_info():
for index,info in enumerate(shopping_list,0):
print ('%s | name: %s | money: %s' % (index,info[0],info[1])) def shopping_start():
while True:
shop_num = int(input('please input number [88:quit]:'))
if shop_num == 88:
break
shopping_car[shopping_list[shop_num][0]] = shopping_list[shop_num][1] def shopping_stop():
global shopping_total_money
print ('.............shopping list open...........')
for k,v in shopping_car.items():
print ('name: %s money: %s' % (k,v))
shopping_total_money += v
print('............shopping list end.......')
print ('total cost [%s] yuan' % (shopping_total_money)) def shopping_close():
global shopping_total_money
make_sure = input('make sure [y|n]')
if make_sure == 'y':
print ('thank you come on')
for k, v in shopping_car.items():
log_info = 'name: %s money: %s' % (k, v)
shopping_log_add(log_info)
shopping_total_money = 0
shopping_car.clear() elif make_sure == 'n':
print ('your no make sure')
print ('clear shopping car .....')
shopping_total_money = 0
shopping_car.clear() def shopping_run():
global name
welcome_info()
shopping_list_info()
print ('________________________________')
name = input('inout your name:')
shopping_start()
shopping_stop()
shopping_close() if __name__ == "__main__":
while True:
shopping_run()
time.sleep(2)
os.system('cls')

记录日志信息:

 2016-10-30 09:21:40 : beijing : name: car money: 1000
2016-10-30 09:21:40 : beijing : name: computer money: 200
2016-10-30 09:21:40 : beijing : name: home money: 10000
2016-10-30 09:21:40 : shanghai : name: phone money: 100
2016-10-30 09:21:40 : shanghai : name: car money: 1000
2016-10-30 09:21:40 : shanghai : name: computer money: 200