0

I need a function that Asks the user for a Stock Symbol and Name pairing then adds it to the Names dictionary. but all I have so far is

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}

thank you anyone who trys to help

asked Dec 12, 2014 at 3:25

2 Answers 2

1

This should work:

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

Output

what is the symbol of your stock: abc
what is the name of your stock: xyz
{'abc': 'xyz'}
answered Dec 12, 2014 at 3:28
Sign up to request clarification or add additional context in comments.

1 Comment

@clutchcocobean Please let me know if you face any problem.
0

Is this what you are after? Difficult to know from your question:

dictname = {}
def addname(x,y):
 global dictname
 dictname[x] = y
stocksymbol = input("what is the symbol of your stock: ")
stockname = input("what is the name of your stock: ")
addname(stocksymbol, stockname)
print(dictname)

Prints:

what is the symbol of your stock: some symbol
what is the name of your stock: some name
{'some symbol': 'some name'}
answered Dec 12, 2014 at 3:28

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.