python_week1-2018.7.8 (shopping cart, BMI additions and deletions system)

Source: Internet
Author: User

"""
Functional Requirements:
Require users to enter their own total assets, for example: 2000
Display the list of items, let the user select the item according to the serial number, add the shopping cart
Purchase, if the total amount of goods is greater than the total assets, indicating that the account balance is insufficient, otherwise, the purchase succeeds.
goods = [
{"Name": "Computer", "Price": 1999},
{"Name": "Mouse", "Price": 10},
{"Name": "Yacht", "Price": 20},
{"Name": "Beauty", "Price": 998},
]

"""

goods = [
{"Name": "Computer", "Price": 1999},
{"Name": "Mouse", "Price": 10},
{"Name": "Yacht", "Price": 20},
{"Name": "Beauty", "Price": 998},
]

money = Int (input ("Please enter your total assets:"))
Count = 1
Lis = [1,2,3,4]
For I in Goods:
Print (' {} {} {} '. Format (count, I.get ("name"), I.get ("Price"))
Count + = 1

LST = []
While True:
A = input ("Please enter the product code you want to purchase:"). Upper ()
If a = = "Q":
Print ("Input end!!")
Break
elif Int (a) in LIS:
A = Int (a)
If Money-goods[a-1].get ("price") >= 0:
Lst.append (a)
Print ("The--%s--item has been successfully added, the price of the commodity is--%s--, you have the remaining--%s--"% (A, goods[a-1].get ("Prices"), Money-goods[a-1].get ("value"))
Money = Money-goods[a-1].get ("Price")
Else
Print ("Insufficient balance to purchase!")
Break

Else
Print ("Input error!!! Please re-enter: ")
Print (LST)
Print ("You also have the remaining--{} dollar--You have now successfully purchased the following products:". Format (Money))
For I in LST:
Print (Goods[i-1].get ("name"))
Print ("End of shopping!")




# 1. Create and export the menu, the menu is immutable. So use tuples
# menus = ("1, Input", "2, Query", "3, delete", "4, Modify", "5, Exit")

# Store user's information ID: {' name ': ' Name ', ' weight ': weight, ' height ': height}
# For example: There are currently two user information: 1. Wang Feng, 2. Zhang ziyi
# Storage structure:
# {
# 1:{' name ': ' Wang Feng ', ' weight ':, ' height ': 1.8, ' BMI ': 24.7},
# 2:{' name ': ' Zhang Ziyi ', ' weight ': ' Height ': 1.65, ' BMI ': 18.4}
# }
# bodies = {}
#
# body_id = 1 # numbering starting from 1

# body mass index (BMI) = weight (kg) ÷ (height (m) x height (m))
# Weight in units: KG
# Height in units: M
# Requirements: first. Print menu, and the user enters the selected menu item
# input 1: Enter the entry link. Users need to enter: name, height, weight.
# The BMI index is calculated by the program. Saved in the bodies dictionary. The first user's ID is 1, the second one is 2, and so on
# After the entry is complete. Prompts the user whether to continue the entry. If you choose Yes, continue with the entry until the user enters No. Then return to the main menu
# Enter 2: Enter the query link, prompting the user to enter the ID of the person to query. If not present, give the hint if it exists. Displays all information about the user (first name, height, weight, BMI)
# then prompt the user whether to continue the query. If you choose Yes, continue with the query until the user enters no, and returns to the main menu
# Enter 3: Enter the delete link, prompting the user to enter the ID of the person to be deleted, if the ID does not exist, give a hint, if present, perform the delete operation. And you are prompted to delete successfully.
# then prompt the user whether to continue to delete, if yes, continue to let the user select the ID to delete until the user input No, return to the main menu
# Input 4: Enter the modification link, first let the user enter the ID of the person to be modified, according to the ID to find the user information, if not present, give and prompt, if present, the user original information to print,
# then prompt the user to enter a new name, height, weight. The BMI index is recalculated by the program. and save the new information in the bodies. At the same time to show users new user information
# then prompts the user to continue the modification and, if so, continues to require the user to enter the ID information. Until the user enters no, return to the main menu.
# Enter 5: program exits.
# Enter any other content. are not lawful to be prompted. Let the user re-enter
body_id = 1
DIC = {}
While True:
Menus = ("1, Input", "2, Query", "3, delete", "4, Modify", "5, Exit")
Print ("Welcome to System!!!")
For I in menus:
Print (i)
num = input ("Please enter what you want to do according to the menu number:")
if num = = "1": # #添加用户信息
#录入系统
Print ("You are here--input--Interface:")
While True:
Bodies = {}
Name = input ("Please enter your name:")
bodies["name"] = Name
hight = Int (input ("Please enter your height (cm):"))
bodies["hight"] = hight
weight = Int (Input ("Please enter your weight (Kg):"))
bodies["weight"] = weight
BMI = Weight/hight * 2
bodies["BMI" = BMI
DIC[BODY_ID] = bodies
body_id + = 1
CHOSE1 = Input ("Choose whether or not to enter:")
Print (Bodies)
Print (DIC)
if chose1 = = "Yes":
Continue
Else
Break
# print (Bodies)
# Print (DIC)

elif num = = "2": # #查看用户信息模块
While True:
Print (Bodies)
Print (DIC)
Print ("You are here--query--Interface:")
chose2 = Int (input ("Please enter the person ID number you want to query:"))
Print (Dic.get (CHOSE2, "This ID does not exist")
CHOSE1 = Input ("Choose whether you want to also query:")
if chose1 = = "Yes":
Continue
Else
Break

elif num = = "3": # #删除用户信息模块
While True:
Print ("You are now--delete--Interface:")
Print (Bodies)
Print (DIC)
CHOSE3 = Int (input ("Please enter the person ID number you want to delete:"))
Print (Dic.keys ())
If CHOSE3 in Dic.keys ():
ret = Dic.pop (CHOSE3)
Print ("The content you deleted is: {}". Format (ret), "Delete succeeded!!!")
Else
Print ("No This ID:")
CHOSE1 = Input ("Select if you want to delete:")
if chose1 = = "Yes":
Continue
Else
Break


elif num = = "4": #修改用户信息模块
Print ("You are now in--modify--Interface:")
While True:
chose4 = Int (input ("Please enter the person ID number you want to modify:"))
Print (Dic.keys ())
If Chose4 in Dic.keys ():
Print (Dic[chose4])
Bodies = {}
Name = input ("Please enter a new name:")
bodies["name"] = Name
hight = Int (input ("Please enter a new height (cm):"))
bodies["hight"] = hight
weight = Int (Input ("Please enter a new weight (Kg):"))
bodies["weight"] = weight
BMI = Weight/hight * 2
bodies["BMI" = BMI
DIC[CHOSE4] = bodies
body_id + = 1
Else
Print ("No This ID:")
Continue
CHOSE1 = Input ("Select whether you want to continue modifying:")
Print (Bodies)
Print (DIC)
if chose1 = = "Yes":
Print ("Please make the next modification!!")
Else
Break
elif num = = "5":
Print ("You quit the program, welcome to use it next time!")
Break
Else
Print ("You mistyped!!")

python_week1-2018.7.8 (shopping cart, BMI additions and deletions system)

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.