Python self-study log-Basic (2)

Source: Internet
Author: User

Actually don't have to write some basic things, these things can be referred to

Http://www.runoob.com/python3/python3-tutorial.html

This web site to learn

Here I'll share a piece of code for you,

One, demand

1. Establish a management system, ' fruit management '

2. Can query, add, change price, delete, exit.

3. Follow your number to proceed accordingly.

Here's my Code.

Two, the code

# coding = Utf-8

name = ' Fruit Management '

1. Check Fruit

2. Add fruit

3. Price change

4. Delete fruit

0. Exit Please select the operation: "

Sys_sg = {} # all Fruits

While TRUE:SYS_SR = input (name)

if Sys_sr = = ' 0 ':

Break # Exit Loop

Elif sys_sr not in [' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 0 ']:

Print (' {0} selected operation does not exist '. Format (SYS_SR))

elif Sys_sr = = ' 2 ':

Sys_xx = input (' Please enter fruit information (id,name,cnt,price,sale_top): \ n ')

Sys_xx = Sys_xx.split (', ')

If Len (sys_xx)! = 5:

Print (' Input information is incomplete, please try again! ‘)

Continue

Sys_zd = {' name ': sys_xx[1], ' cnt ': Int (sys_xx[2]), ' Price ': float (sys_xx[3]), ' Sale_top ': float (sys_xx[4])}

Sys_sg[sys_xx[0]] = Sys_zd

Print (' Add success! ')

Elif Sys_sr in [' 1 ', ' 3 ', ' 4 ']:

sys_id = input (' Enter fruit number: ')

Sys_zd = Sys_sg.get (sys_id)

If Sys_zd is None:

Print (' {0} does not have this effect '. Format (sys_id))

elif Sys_sr = = ' 1 ':

Print (SYS_ZD)

elif Sys_sr = = ' 3 ':

Sys_price = input (' Please enter the latest price of fruit: ')

sys_zd[' price ' = float (sys_price) # change the latest prices

Print (' Price changed successfully! ')

elif Sys_sr = = ' 4 ':

Sys_sg.pop (sys_id)

Print (' Delete succeeded! ')

Print (' Exiting program ... ')

Three, explain

English proficiency is limited, probably can only be written in this way, if you can optimize, please the big guy can express their views.

Python self-study log-Basic (2)

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.