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

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

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

本文實(shí)例為大家分享了python淘寶購(gòu)物系統(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)動(dòng)鞋','price':200,'count':120},
{'name':'vivo','price':2000,'count':200},
{'name':'自行車','price':2100,'count':300}]

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

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

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


#登錄
def log_in():
 print('~'*10,'登錄賬號(hào)','~'*10)
 while True:
 user_account = input('請(qǐng)輸入您的賬號(hào)')
 user_password = input('請(qǐng)輸入您的密碼')
 if user_account != account:
 print('賬號(hào)有誤')
 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('請(qǐng)選擇您要執(zhí)行的操作:')
 print('1、查詢商品')
 print('2、查看購(gòu)物車')
 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

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


#展示購(gòu)物車
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('商品單價(jià):%d'%shoppingCar[i][key])
 elif key == 'count':
 print('商品數(shù)量:%d'%shoppingCar[i][key])
 elif key == 'total':
 print('商品總價(jià):%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()

#清空購(gòu)物車
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('請(qǐng)輸入密碼')
 charge_password1 = input('請(qǐng)確認(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('請(qǐng)輸入密碼')
 if user == charge_password:
 while True:
  chargeMoney = int(input('請(qǐng)輸入充值金額'))
  if chargeMoney % 100 != 0:
  print('請(qǐng)輸入充值金額')
  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('商品單價(jià):%d'%order[i][key])
 elif key == 'count':
 print('商品數(shù)量:%d'%order[i][key])
 elif key == 'total':
 print('商品總價(jià):%d'%order[i][key])
 cost_money += order[i][key]
 print('總共花費(fèi)%d元'%cost_money)


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


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


#其他功能
def other():
 print('△'*30)
 print('請(qǐng)選擇您要執(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('請(qǐng)重新登錄')
 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()

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(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編寫(xiě)簡(jiǎn)單的定時(shí)器的方法

    用Python編寫(xiě)簡(jiǎn)單的定時(shí)器的方法

    這篇文章主要介紹了用Python編寫(xiě)簡(jiǎn)單的定時(shí)器的方法,主要用到了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存儲(chǔ)json數(shù)據(jù)發(fā)生亂碼的解決方法

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

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

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

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

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

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

    django 外鍵model的互相讀取方法

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

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

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

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

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

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

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

最新評(píng)論

南汇区| 大港区| 错那县| 惠东县| 余姚市| 田东县| 正宁县| 涞水县| 金秀| 五河县| 永福县| 宣恩县| 汶川县| 合江县| 冕宁县| 合山市| 江阴市| 镇雄县| 钦州市| 陈巴尔虎旗| 竹溪县| 温泉县| 厦门市| 玛多县| 土默特右旗| 长武县| 衢州市| 乌恰县| 彩票| 富阳市| 蒲城县| 彭水| 苏尼特左旗| 长沙县| 郴州市| 宜宾县| 兴安县| 平邑县| 平和县| 凤台县| 溧阳市|