0

i am making a something on the raspberry pi that will give you stock prices. here is the code:

import ystockquote
tickerSymbol = 'ADSK'
allInfo = ystockquote.get_all(tickerSymbol)
print tickerSymbol + " Price = " + allInfo["price"]

I first had to download ystockquote on the pi to get the stockquotes from yahoo finance. The tickerSymbol is where you type in the company's name(abbreviation, ADSK is autodesk). what i want to do is manually type in the company abbreviation and then it will provide the price. i have tried things that i thought would work. not the experienced though with python than i am with c++.

1
  • use raw_input()(Python 2.x) or input() (Python3.x) to get input from the keyboard. Commented Mar 6, 2015 at 15:12

2 Answers 2

2

Use raw_input() for Python 2.x and input() for Python 3.x

Demo:

>>> user_input = raw_input("Enter value:")
Enter value:test
>>> print user_input
test
>>> 

Use break statement if you want to get User Input in any loop to come out from the loop.

Demo

>>> while True:
...    user_input = raw_input("Enter value:")
...    if user_input.lower()=="no":
...         print "break while loop"
...         break
...    print "User Value:", user_input
... 
Enter value:test
User Value: test
Enter value:test1
User Value: test1
Enter value:No
break while loop
>>> 
Sign up to request clarification or add additional context in comments.

Comments

1

You could use something like this:

while True:
    tickerSymbol = raw_input('Enter a stock symbol: ')
    allInfo = ystockquote.get_all(tickerSymbol)
    print tickerSymbol + " Price = " + allInfo["price"]

Encapsulating this in a while True: loop will allow the user to continue to get new quotes without having to restart the program.

Also as stated above use raw_input() for 2.x and input() for 3+

Comments

Your Answer

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.