2016-08-22 3 views
0

Ich versuche, eine Liste zu nehmen, share_list, und dann nacheinander durch die Liste und produzieren eine Ausgabe, die auf das Ergebnis zugeschnitten ist. Ich habe zwei Probleme: Ich weiß nicht, wie man durch die Liste eine for-Schleife, und ich erhalte diese Störung:TypeError: unorderable Typen: str() <= int()

Traceback (most recent call last): 
    File "C:\Users\Andrew\Documents\Python Projects\DataAnalytics\algorithm.py", line 9, in <module> 
    if check_pb_ratio.get_price_book() <= 1: 
TypeError: unorderable types: str() <= int() 
from yahoo_finance import Share 

share_list = ['AAPL', 'GEVO', 'PTX'] 


for ticker in share_list: 
    check_pb_ratio = Share(share_list[0]) 

    if check_pb_ratio.get_price_book() <= 1: 
     print(str(check_pb_ratio.get_price_book())) 
    else: 
     print("P/B Ratio is too high.") 
+0

Es scheint, dass 'check_pb_ratio.get_price_book()' eine Zeichenfolge ist. versuche es vor dem 'if' zu drucken. – xmcp

+1

'share_list [0]' -> 'ticker',' check_pb_ratio.get_price_book() '->' float (check_pb_ratio.get_price_book()) '. Erwägen Sie, Google und/oder ein Python-Tutorial zu verwenden. –

Antwort

0

Der Grund dafür ist, dass die Funktion check_pb_ratio.get_price_book() zurückkehrt eine Zeichenkette, keine int. Python will nicht die Ähnlichkeit wissen, zwischen ‚1‘ und 1
die Art und Weise Also, um es zu beheben ist: in int() oder float() um check_pb_ratio.get_price_book()

0

Dank @Rawing

Dieser Code funktioniert jetzt, ich muss nur ein NoneType-Problem beheben. Vielen Dank!

from yahoo_finance import Share 

share_list = ['AAPL', 'GEVO', 'PTX'] 


for ticker in share_list: 
    check_pb_ratio = Share(ticker) 

    if float(check_pb_ratio.get_price_book()) <= 1: 
     print(str(check_pb_ratio.get_price_book())) 
    else: 
     print("P/B Ratio is too high.") 
Verwandte Themen