Python Learning notes-shopping cart

Source: Internet
Author: User

Import Collections
def login ():
li=[' Xiaohei ', ' 123456 ', ' Xiaohuang ', ' 23456 ', ' Xiaoli ', ' 34567 ']
dic={}
C=0
While True:
For I in range (Len (LI)):
if (i+1)%2==1:
Dic[str (Li[i])]=str (li[i+1])
Else
Pass
print ' Welcome to the shopping system! ‘
User=raw_input ("Please enter your user name:")
If user in Dic.keys ():
While c<3:
C+=1
Passwd=raw_input ("Please enter your password:")
If dic[user]==passwd:
print ' Welcome to login! ‘
Return
Else
print ' Password is wrong! Please re-enter '
Else
print ' Input password error 3 times, password is frozen '
Quit ()

Else
print ' User name is wrong! Please re-enter '
Def show (n):
A=[] #记录购买信息
Total=0
Sale=collections.namedtuple (' Sale ', ' product price ')
Sales=[] #记录命名元组的列表
Sales2=[] #记录商品名称的列表
Apple=sale (product= ' Apple ', price=99)
Car=sale (product= ' car ', price=999)
Book=sale (product= ' book ', price=100)
Sales.append (apple)
Sales.append (CAR)
Sales.append (book)
Sales2.append (' Apple ')
Sales2.append (' car ')
Sales2.append (' book ')
While True:
For I in Sales:
Print I.product,i.price

Buy=raw_input (' Enter the item you want to buy or exit: ')
If buy== ' exit ':
Gobuy (Total,n)
Else
If buy in Sales2:
Buy=locals () [Buy] #将字符串转为变量
Total+=buy.price
A.append (' Selected item%s price%s '% (Buy.product,buy.price))
For I in A:
Print I
print ' Total merchandise:%s '%total
Print 9* '-'
Else
print ' Sorry, no product '
Print 9* '-'
def gobuy (total,n):
N=n-total
print ' balance is%s '%n
Nextbuy=raw_input (' Do you want to continue shopping? y/n ')
If nextbuy== ' y ':
Show (total)
Else
print ' Welcome to come again next time! ‘
Quit ()
If __name__== ' __main__ ':
n=5000
Login ()
Show (N)

Python Learning notes-shopping cart

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.