定义 'name not defined' 时出现错误

Getting an error for 'name not defined' when it has been defined

我正在编写代码让用户输入 items/prices/quantities 以获得购物清单。 while 循环应该继续循环,直到变量不再为真。我在 while 循环 (stop=='true') 之前定义了变量,但它一直作为未定义 'stop' 的错误返回。我已经尝试了各种随机组合,所以代码现在看起来可能很疯狂。下面的代码。谢谢!

grocery_list={}
grocery_history={}

stop == 'true'

while stop == 'true' :
    grocery_item['item_name']=input('Item name:\n')
    grocery_item['quantity']=input('Quantity purchase:\n')
    grocery_item['cost']=input('Price per item:\n')
    grocery_history.append(grocery_item)
    if input('Would you like to enter another item?\nType c for continue or q to quit:\n') == 'q':
       stop=='q'

第 4 行应该是:stop = 'true'

一个=是赋值,==是比较运算符

message = 'Would you like to...'
items = []
while input(message) != 'q':
    items.append({
         'name': nput('Item name:\n'),
         'quantity': int(input('Quantity purchase:\n')),
         'cost': input('Price per item:\n'),
    })