如何将伪代码转换为Python 2.x?

2024-04-26 07:53:03 发布

您现在位置:Python中文网/ 问答频道 /正文

以下是过度生产管理系统的伪代码:

Add memory library module

Prompt; 1)search for item, 2)add over produced item

If search for item
Prompt input item number

    If item number in database print available quantity

    Else print “None available”

Else if add over produced item
Prompt input item number
    If item number in database
    Prompt “how many”
    Add quantity to inventory
    Else if item number not in inventory
    Add item to inventory with quantity

Tags: inaddnumberforinputsearchifitem
1条回答
网友
1楼 · 发布于 2024-04-26 07:53:03
db = {}
while True:
    if raw_input("Prompt; 1)search for item, 2)add over produced item > ") == "1":
        item = raw_input("Item number? > ")
        if item in db:
            print("Available: " + str(db[item]))
        else:
            print("None available")
    else:
        item = raw_input("Item number? > ")
        qty = int(raw_input("Quantity? > "))
        if item in db:
            db[item] += qty
        else:
            db[item] = qty

相关问题 更多 >