我需要一个函数,要求用户输入“股票代号”和“名称”配对,然后将其添加到“名称”字典中。但到目前为止,我所拥有的只是
def addname(x,y):
dicname = {(x): (y)}
return dicname;
stocksymbol = (input("what is the symbol of your stock"))
stockname = (input("what is the name of your stock"))
addname(stocksymbol, stockname)
dnames = {dicname}
谢谢任何尝试帮助的人
这应该工作:
def addname(x,y):
dicname = {(x): (y)}
return dicname
stocksymbol = (raw_input("what is the symbol of your stock: "))
stockname = (raw_input("what is the name of your stock: "))
dnames = addname(stocksymbol, stockname)
print dnames
输出
what is the symbol of your stock: abc
what is the name of your stock: xyz
{'abc': 'xyz'}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句