SoFunction
Updated on 2024-10-29

python implementation of the simple taobao shopping

This article example shares a simple python Taobao shopping for your reference, the details are as follows

Without further ado, the source code is attached

def jm():#Define parent class interface functionality
  print("*****1 Today's Sale *****")
  print("*****2 Women's Clothing *****")
  print("*****3 Men's Clothing *****")
  print("*****4 Food Tea Wine *****")
  print("*****5 Closing *****")
def jr():Today's Specials in the #DefinitiveFatherhood category
  print("***1 Sweater Dress $59***")
  print("***2 Sneakers $69***")
  print("***3 Trench Coat $99***")
def ms():#DingYiFu Class Cuisine
  print("*****1 Coffee $50 *****")
  print("*****2 Snack Bundle $49 *****")
  print("*****3 lemons $30 *****")
dic={}#BuyToday'sSale
dic2={}#GourmetBuy
dl=0# of logins
xf=0How much to spend on #BuySale
g=0#How much to spend on food
print("********* Welcome to Mobile Taobao *********")#Print to Taobao page
a=int(input("Please enter the function you want to select 1, Login 2, Logout:"))#Select the function you want to accomplish
while dl<=2:
  if a==1:#When selecting the function to log in
    mz=input("Please enter user name:")#Enter account number
    mm=input("Please enter the password:")#Enter password
    if mz!="Zhang San":#To determine if the account is Zhang San
      print("Account number error.")# If it is not outputting a login error
    elif mz=="Zhang San" and mm!="wasd":# If it's Zhang San, the password is not wasd #
      print("Wrong password.")# Output password error
    elif mz=="Zhang San"and mm=="wasd":# If it's Zhang San, the password is wasd #
      print("Login successful.")# Output login success
      dl += 1
      print("-------- Welcome to Mobile Taobao --------")#Print the page after entering Taobao
      jm()# Introducing functional interfaces
      gn=int(input("Please enter the function number you wish to select."))# Select the function on the interface
      while True:# Infinite loop
        if gn==1:#When Features Select Today's Deals
          jr()# Introducing the Sale of the Day parent class
          jq1=int(input("Please enter the number of the item you want to buy:" ))#Select the item number you want to buy
          if jq1==1:#Judging when to buy 1
            w="Sweater dress."# Items are dresses
            xf=59# Spend $29
            ({w: xf})# Add keys and values to the dic dictionary
          if jq1==2:#Judging when to buy 2
            w="Sneakers."# Items are sneakers
            xf=69#Items priced at $69
            ({w: xf})# Add keys and values to the dic dictionary
          if jq1==3:# When selecting function 3
            w="Trench coat."# Items are trench coats
            xf=99#Price is $99
            ({w:xf})# Add keys and values to the dic dictionary
          xz=input("Purchase successful whether to continue :y/n")#Choose whether you want to go ahead with the purchase
          if xz=="n":# When the choice is no
            print("Current cart items have %s"%(dic))# Output dictionary, what was purchased and price
            jm()# Introducing the interface parent class
            gn = int(input("Please enter the function number you wish to select."))#Select the features you want
        if gn==2:#When selecting function 2
          print("Women's clothing is sold out today.")#Printed women's clothing is sold out
          # ps this one function and the next three function editor lazy did not write, but write the way is the same as the 1st function
          xz = input("Purchase failed to continue :y/n")#Whether to proceed with the purchase
          jm()#Introduce interface functionality
          gn = int(input("Please enter the function number you wish to select."))#Select the function of the interface
        if gn==3:
          print("Men's clothing is sold out today.")
          xz = input("Purchase failed to continue :y/n")
          jm()
          gn = int(input("Please enter the function number you wish to select."))
        if gn==4:#When the function is 4
          ms()#Introduce a food interface
          jq2=int(input("Please enter the number of the item you wish to purchase."))#Select the interface you want to buy
          if jq2==1:
            x="Coffee."
            g=50
            ({x:g})
          if jq2==2:
            x="Snack Pack."
            g=49
            ({x:g})
          if jq2==3:
            x="Lemon."
            g=30
            ({x:g})
          xz = input("Purchase successful whether to continue :y/n")
          if xz == "n":
            print("Current cart items have %s" % (dic2))
            jm()
            gn = int(input("Please enter the function number you wish to select."))
        if gn==5:#When function 5 is selected
          print("This purchase is as follows Item name: Price")#Print purchases and prices
          print(dic)#OutputToday's Sale
          print(dic2)#Output Gourmet
          sum=xf+g#Price of clothes + price of food = total spending
          print(sum)How much is the total consumption of #output
          break# End the infinite loop

  if a==2:#When choosing a function to exit Taobao
    print("Welcome to Taobao next time.")
    breakend of loop

This is the whole content of this article, I hope it will help you to learn more.