Python Code Note points:1. Note Indent2.if, while and other statements remember to add a colon:3. Note the use of spaces4. When writing code through PYCHARM, note the prompt informationData:goods = [{"Name": "Computer", "Price": 1999},{"Name": "Mouse", "Price": 10},{"Name": "Yacht", "Price": 20},{"Name": "Beauty", "Price": 998},......]Functional Requirements:Basic requirements:1, after starting the program, enter the user name password, let the user e
Requirements:1, write a shopping cart sequence code2. Use the list to store the product list of the mall and save it to the list Shopping_mail3, the shopping cart list is Shopping_cart4, the user first enter the salary amount, judge the input as the number5, the user from the mall
#all small code hereproduct_list= [['Iphone7', 5800], ['Coffee', 30], ['Pimple Soup', 10], ['Python Book', 99], ['Bike', 199], ['ViVo X9', 2499]]shopping_cart=[]salary= Int (Input ("Input your Salary:")) whileTrue:menu= u" "-------Good shopping---------\033[32;1m 1. Enter the serial number to buy the goods into the
after starting the programProduct_list = [ ('iphone', 5800), ('Bike', 800), ('Coffee', 31), ('Macbook Pro', 12000), ('Alex Python', 81), ('a', 120)]ifSalary.isdigit (): Salary=Int (Salary) whileTrue: forIndex,iteminchEnumerate (product_list):#take data and subscript from a list of items #Print (Product_list.index (item), item) Print(index,item) User_choice= Input ("Choose the item you want to buy? >>>:")
() # Create a dictionary to store the products that the user has purchased, and the number of items purchased Whiletrue:remain_sum=input ("Please enter your balance:") ifremain_sum.isdigit (): print (" Your shopping cart is empty ..... ") remain_sum=int (remain_sum) loop=0whileTrue: ifloop==0: #只有用户刚进入的时候显示余额, That is, the balance is printed the first time the while loop is executed print ("|-----------|
Program: Shopping Cart ProgramDemand:
After you start the program, let the user enter the payroll, and then print the list of items
Allow users to purchase items based on their product number
After the user selects the product, checks whether the balance is enough, enough on the direct debit, enough to remind
You can exit at any time to print the purchased goods and balances when exitin
Shopping Cart Procedureproduct_list = [(' Mac ', 9000),(' Kindle ',(' Tesla ', 900000),(' Python book ',(' bike ', '),]saving = input (' Please input your money: ')Shopping_car = []if Saving.isdigit (): #验证输入的是否为数字格式, if established then continuesaving = Int (saving)While True:#打印商品内容# for I in Product_list:# Print (Product_list.index (i), i)# for I in Enumerate
Python Shopping Cart
Demand
The user name and password are stored in the file in the following format: xxx|xxx
Start the program, log in first, log in successfully let the user enter the salary, and then print the product list, failed to log in again, more than three times to quit the program
Allow users to purchase items based on
Shopping Cart procedure, the program requirements are as follows:1. Product Information-quantity, unit price, name2. User Information-account number, password, balance3. User can Recharge4. Shopping history Information5. Allow users to purchase multiple items at a time6. Reminders when the balance is insufficient7. When the user exits, output this
Product_list = [("iphone", 5800),("MOC Pro", 9800),("Bike", 800),("Coffee", 31),("Linux book", 80)]Shopping_list =[]Salary = input ("Input your Salary:")ifSalary.isdigit ():# used to determine if the input string is a number form true if yessalary = Int (salary)While True:# for item in Product_list: #for item in range product_list: wrong spelling# Way One: print (Product_list.index (item), item) #通过 Index to display its subscript for the product number forIndex,iteminchEnumerate (product_list):#
Shopping cart Program Job requirements:1, after starting the program, enter the user name password, if it is the first time to log in, let the user enter wages, and then print the product list2. Allow users to purchase goods according to the product number3, the user selects the goods, checks whether the balance is enough, enough on the direct debit, not enough on the reminder4, can withdraw at any time, ex
This article mainly introduces part of the Python shopping cart user code, which has some reference value. interested friends can refer to the knowledge points: file reading, write operations, if judgment, for loop
Salary = input ("Enter your salary:") bought_list = [] product_list = {}with open ("product_list", "r", encoding = "UTF-8") as f1: for item in f1: p_
#! /usr/bin/env python#-*-coding:utf-8-*-#-*-author:leon-*-"" "Functional Requirements: Require the user to enter total assets, for example: 2000 Display the product list, let the user select items according to the serial number, add shopping cart purchase, If the total amount of goods is greater than the total assets, the account balance is insufficient, otherwi
item and determine whether the price of the product is less than or equal to the wageShopping_list.append (P_item)#conditional, put the purchased items into an empty listSalary-=p_item[1]#subtract the salary from the price of the goods purchased, the result is assigned to salary, the result is the remaining balance Print("Added%s To shopping cart, you are current balance is%s"%(p_item,sa
Requirements:1. User input after payroll display product List2. Select items by Product number3. Print the list of items and the remaining wages after selecting the itemThe code is as follows:# Coding=utf-8Product_list = [(' iphone ', 5800),(' Mac Pro ', 9800),(' Bike ', 800),(' Watch ', 10600),(' Coffee ', 31),(' Alex python ', 120),]Shopping_list = [] #购物车Salary = input ("Input your Salary:")If Salary.isdigit (): #判断工资是否为数字salary = Int (salary)While
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.