最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python實(shí)現(xiàn)淘寶購物系統(tǒng)

 更新時間:2019年10月25日 15:49:31   作者:無冇  
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)簡易的淘寶購物系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了python淘寶購物系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

代碼如下:

#剛創(chuàng)建賬戶所擁有的錢
money = 0


#定義商品列表
goods_list = [
{'name':'iphone','price':4500,'count':40},
{'name':'電腦','price':7000,'count':100},
{'name':'平板','price':5000,'count':60},
{'name':'羽絨服','price':500,'count':80},
{'name':'西服','price':1000,'count':90},
{'name':'運(yùn)動鞋','price':200,'count':120},
{'name':'vivo','price':2000,'count':200},
{'name':'自行車','price':2100,'count':300}]

#創(chuàng)建空的購物車
shoppingCar = []

#創(chuàng)建訂單列表
order = []

#注冊賬戶
def register():
 print('→'*8,'注冊賬號','←'*8)
 global account
 global password
 account = input('請輸入賬號')
 password = input('請輸入密碼')
 password1 = input('請確認(rèn)密碼')
 while True:
 if password == password1:
 print('→'*8,'注冊成功','←'*8)
 log_in()
 break
 else:
 password = input('請重新輸入密碼')
 password1 = input('請確認(rèn)密碼')


#登錄
def log_in():
 print('~'*10,'登錄賬號','~'*10)
 while True:
 user_account = input('請輸入您的賬號')
 user_password = input('請輸入您的密碼')
 if user_account != account:
 print('賬號有誤')
 elif user_account == account and user_password != password:
 print('密碼有誤')
 else:
 print('~'*10,'登錄成功','~'*10)
 show_menu()
 break

#展示商品列表
def show_name():
 print('❤'*30)
 a = 0
 for i in range(0,len(goods_list)):
 for key in goods_list[i].keys():
 if key == 'name':
 a += 1
 print(goods_list[i][key], end = '\t')
 if a % 4 ==0 :
 print('')
 print('❤'*30)


#選擇操作
def show_menu():
 while True:
 print('※'*20)
 print('請選擇您要執(zhí)行的操作:')
 print('1、查詢商品')
 print('2、查看購物車')
 print('3、查看訂單')
 print('4、其他功能')
 print('5、退出系統(tǒng)')
 print('※'*20)
 choice = int(input())
 if choice == 1:
 show_name()
 search_shopping()
 elif choice == 2:
 show_shoppingCar()
 elif choice == 3:
 show_order()
 elif choice == 4:
 other()
 else:
 print('歡迎下次光臨!')
 break

#添加商品至購物車
def add_shopping(name,price,count,total):
 dict = {}
 dict['name'] = name
 dict['price'] = price
 dict['count'] = count
 dict['total'] = total
 shoppingCar.append(dict)


#展示購物車
def show_shoppingCar():
 global money
 NeedMoney = 0
 for i in range(0,len(shoppingCar)):
 for key in shoppingCar[i].keys():
 print('*'*30)
 if key == 'name':
 print('商品名稱:'+shoppingCar[i][key])
 elif key == 'price':
 print('商品單價:%d'%shoppingCar[i][key])
 elif key == 'count':
 print('商品數(shù)量:%d'%shoppingCar[i][key])
 elif key == 'total':
 print('商品總價:%d'%shoppingCar[i][key])
 NeedMoney += shoppingCar[i][key]
 print('一共需花費(fèi)%d元'%NeedMoney)
 if money >= NeedMoney:
 money -= NeedMoney
 pay_shopping()
 print('一共花費(fèi)%d元'%NeedMoney)
 else:
 print('余額不足')
 charge_money()

#清空購物車
def pay_shopping():
 print('是否支付 yes / no')
 user = input('')
 if user == 'yes':
 print('支付成功')
 order.extend(shoppingCar)
 shoppingCar.clear( )



#設(shè)置充值密碼
def charge_pwd():
 global charge_password
 global money
 print('❀'*30)
 charge_password2 = input('請輸入密碼')
 charge_password1 = input('請確認(rèn)密碼')
 while True:
 if charge_password1 == charge_password2:
 charge_password = charge_password1
 print('❀'*10,'設(shè)置成功','❀'*10)
 show_menu()
 break


#充值金額
def charge_money():
 global money
 print('是否充值 yes / no')
 user = input('')
 if user == 'yes':
 while True:
 user = input('請輸入密碼')
 if user == charge_password:
 while True:
  chargeMoney = int(input('請輸入充值金額'))
  if chargeMoney % 100 != 0:
  print('請輸入充值金額')
  else:
  money += chargeMoney
  print('充值成功')
  break
 break
 else:
 print('密碼有誤')



#添加至訂單

def add_order(name,price,count,total):
 dict = {}
 dict['name'] = name
 dict['price'] = price
 dict['count'] = count
 dict['total'] = total
 order.append(dict)



#展示訂單
def show_order():
 cost_money = 0
 #總共花費(fèi)的錢
 for i in range(0,len(order)):
 for key in order[i].keys():
 print('*'*50)
 if key == 'name':
 print('商品名稱:'+order[i][key])
 elif key == 'price':
 print('商品單價:%d'%order[i][key])
 elif key == 'count':
 print('商品數(shù)量:%d'%order[i][key])
 elif key == 'total':
 print('商品總價:%d'%order[i][key])
 cost_money += order[i][key]
 print('總共花費(fèi)%d元'%cost_money)


#查找商品
def search_shopping():
 name = input('請輸入您要查詢的名稱:')
 isExist = False
 for i in range(0,len(goods_list)):
 if isExist:
 isExist = False
 break
 dict = goods_list[i]
 if dict['name'] == name:
 print('商品名稱:'+name)
 print('商品單價:%d'%dict['price'])
 print('商品庫存:%d'%dict['count'])
 if dict['count'] != 0 : 
 print('請選擇一下功能:\n1、購買\n2、添加至購物車\n3、返回上一項')
 choice = int(input())
 if choice == 1:
  buy_shopping(dict)
  isExist = True
 elif choice == 3:
  search_shopping()
 elif choice == 2:
  num = int(input('請選擇添加至購物車的數(shù)量:'))
  while True:
  if num > dict['count']:
  print('超出總量限制,請重新輸入!')
  num = int(input('請選擇添加至購物車的數(shù)量:'))
  else:
  add_shopping(dict['name'],dict['price'],num,dict['price']*num)
  isExist = True
  print('添加成功')
  break
 else:
  print('輸入有誤,再見!')
 else:
 if i == len(goods_list)-1:
 print('該商品不存在,請重新選擇功能!')


#購買商品
def buy_shopping(dict):
 global money
 if dict['count'] == 0:
 print('該商品已售空,請選擇其他商品')
 else:
 while True:
 num = int(input('請輸入購買的數(shù)量:'))
 if num <= dict['count']:
 needMoney = num * dict['price']
 if money < needMoney:
  print('余額不足,請充值或修改購買數(shù)量!')
 else:
  money -= needMoney
  dict['count'] -= num
  print('購買成功!')
  add_order(dict['name'],dict['price'],num,dict['price']*num)
 break
 else:
 print('庫存不足,請重新輸入')


#其他功能
def other():
 print('△'*30)
 print('請選擇您要執(zhí)行的操作:')
 print('1、充值')
 print('2、更改登錄密碼')
 print('3、更改充值密碼')
 print('4、查看余額')
 choice = int(input())
 if choice == 1:
 print('是否選擇設(shè)置充值密碼 yes/ no')
 a = input()
 if a == 'yes' :
 charge_pwd()
 else:
 charge_money()
 elif choice == 2:
 change_password()
 elif choice == 3:
 changeCPWD()
 elif choice == 4:
 print('余額為%d元'%money)

#更改登錄密碼
def change_password():
 global password
 while True:
 print('☆'*30)
 a = input('輸入新密碼')
 b = input('確認(rèn)密碼')
 print('☆'*30)
 if a == b:
 password = a
 print('請重新登錄')
 log_in()
 break
 else:
 print('重新輸入')


#更改支付密碼
def changeCPWD():
 global charge_password
 while True:
 print('◇'*30)
 a = input('輸入新密碼')
 b = input('確認(rèn)密碼')
 print('◇'*30)
 if a == b:
 charge_password = a
 break
 else:
 print('重新輸入')

register()

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python實(shí)現(xiàn)奇數(shù)列與偶數(shù)列調(diào)換的方法詳解

    Python實(shí)現(xiàn)奇數(shù)列與偶數(shù)列調(diào)換的方法詳解

    這篇文章主要為大家詳細(xì)介紹了如何利用Python實(shí)現(xiàn)df的奇數(shù)列與偶數(shù)列調(diào)換位置,比如A列,B列,調(diào)換成B列,A列,感興趣的小伙伴可以了解一下
    2022-05-05
  • 用Python編寫簡單的定時器的方法

    用Python編寫簡單的定時器的方法

    這篇文章主要介紹了用Python編寫簡單的定時器的方法,主要用到了Python中的threading模塊,需要的朋友可以參考下
    2015-05-05
  • Python可變與不可變數(shù)據(jù)和深拷貝與淺拷貝

    Python可變與不可變數(shù)據(jù)和深拷貝與淺拷貝

    這篇文章主要介紹了Python可變與不可變數(shù)據(jù)和深拷貝與淺拷貝,拷貝函數(shù)是專門為可變數(shù)據(jù)類型list、set、dict使用的一種函數(shù),更多相關(guān)內(nèi)容,需要的小伙伴可以參考一下
    2022-04-04
  • Python存儲json數(shù)據(jù)發(fā)生亂碼的解決方法

    Python存儲json數(shù)據(jù)發(fā)生亂碼的解決方法

    當(dāng)使用json.dump()把python對象轉(zhuǎn)換為json后存儲到文件中時,文件可能會出現(xiàn)亂碼的問題,本篇文章可以幫助您解決亂碼問題,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2023-09-09
  • tesseract-ocr使用以及訓(xùn)練方法

    tesseract-ocr使用以及訓(xùn)練方法

    這篇文章主要介紹了tesseract-ocr使用以及訓(xùn)練方法,結(jié)合圖文形式詳細(xì)分析了tesseract-ocr基本功能、用法、樣本訓(xùn)練與糾錯技巧,需要的朋友可以參考下
    2023-04-04
  • Python字符遍歷的藝術(shù)

    Python字符遍歷的藝術(shù)

    通常我們要遍歷一個字符串中的每個字符,都要先獲取字符串的長度,然后用一個For循環(huán)把每個字符取出,進(jìn)行處理。但是,又是我們的Python,為我們提供了很多便捷的方式去遍歷一個字符串中的字符。
    2008-09-09
  • django 外鍵model的互相讀取方法

    django 外鍵model的互相讀取方法

    今天小編就為大家分享一篇django 外鍵model的互相讀取方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • python如何定義帶參數(shù)的裝飾器

    python如何定義帶參數(shù)的裝飾器

    這篇文章主要為大家詳細(xì)介紹了python如何定義帶參數(shù)的裝飾器,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • Python中的協(xié)程(Coroutine)操作模塊(greenlet、gevent)

    Python中的協(xié)程(Coroutine)操作模塊(greenlet、gevent)

    這篇文章介紹了Python中的協(xié)程(Coroutine)操作模塊(greenlet、gevent),文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-05-05
  • Python命名空間與作用域深入全面詳解

    Python命名空間與作用域深入全面詳解

    命名空間是從名稱到對象的映射,大部分的命名空間都是通過 Python 字典來實(shí)現(xiàn)的,作用域就是一個可以直接訪問命名空間的正文區(qū)域。程序的變量并不是在哪個位置都可以訪問的,訪問權(quán)限決定于這個變量是在哪里賦值的
    2022-11-11

最新評論

宁强县| 故城县| 吉首市| 内乡县| 恭城| 堆龙德庆县| 潞西市| 长子县| 孝义市| 达拉特旗| 嘉祥县| 万宁市| 鞍山市| 诸城市| 微山县| 永安市| 固原市| 雷波县| 庆城县| 元阳县| 泸定县| 武穴市| 视频| 嘉峪关市| 沁水县| 大理市| 元朗区| 锦屏县| 秦皇岛市| 沙河市| 苍梧县| 衡水市| 萨迦县| 海丰县| 麻阳| 渝中区| 凤冈县| 墨脱县| 安福县| 广昌县| 鹰潭市|