Python的一段代码,有没有人看看怎么老是运行不起来,好的必采纳


class Stock():
    def __init__(self):
        self.__symbol=""
        self.__name=""
        self.preClosingPrice=0
        self.curPrice=0
        def oneStock(self,detailContent):
            self.__symbol=detailContent[0],
            self.__name=detailContent[1],
            self.preClosingPrice=detailContent[2],
            self.curPrice=detailContent[3],
        def getStockSymbol(self):
            return(self.__symbol)
        def getStockName(self):
            return(self.__name)
        def getpreClosingPrice(self):
            return(self.preClosingPrice)
        def setpreClosingPrice(self,price):
            self.preClosingPrice = price
        def getcurPrice(self):
            return(self.curPrice)
        def setcurPrice(self,price):
            self.curPrice = price
        def getChangePercent(self):
            x=self.curPrice-self.preClosingPrice
            y=x/self.curPrice
            return(y)
        astock=Stock()
        astock.oneStock(["10001","平头哥芯片",62.82,70.32])
        print(astock.getStockSymbol())
        print(astock.getStockName())
        print(astock.getCurPrice())
        print(astock.getPreClosingPrice())




 
class Stock():
    def __init__(self):
        self.__symbol=""
        self.__name=""
        self.preClosingPrice=0
        self.curPrice=0
    def oneStock(self,detailContent):
        self.__symbol=detailContent[0],
        self.__name=detailContent[1],
        self.preClosingPrice=detailContent[2],
        self.curPrice=detailContent[3],
    def getStockSymbol(self):
        return(self.__symbol)
    def getStockName(self):
        return(self.__name)
    def getpreClosingPrice(self):
        return(self.preClosingPrice)
    def setpreClosingPrice(self,price):
        self.preClosingPrice = price
    def getcurPrice(self):
        return(self.curPrice)
    def setcurPrice(self,price):
        self.curPrice = price
    def getChangePercent(self):
        x=self.curPrice-self.preClosingPrice
        y=x/self.curPrice
        return(y)
astock=Stock()
astock.oneStock(["10001","平头哥芯片",62.82,70.32])
print(astock.getStockSymbol())
print(astock.getStockName())
# print(astock.getCurPrice())  #原
print(astock.getcurPrice())
# print(astock.getPreClosingPrice()) #原
print(astock.getpreClosingPrice())

# 定义函数不能嵌套定义,
#缩进问题
#最后两行调用函数的函数名大小写有误。

注意代码缩进

 
class Stock():
    def __init__(self):
        self.__symbol=""
        self.__name=""
        self.preClosingPrice=0
        self.curPrice=0
    def oneStock(self,detailContent):
        self.__symbol=detailContent[0],
        self.__name=detailContent[1],
        self.preClosingPrice=detailContent[2],
        self.curPrice=detailContent[3],
    def getStockSymbol(self):
        return(self.__symbol)
    def getStockName(self):
        return(self.__name)
    def getpreClosingPrice(self):
        return(self.preClosingPrice)
    def setpreClosingPrice(self,price):
        self.preClosingPrice = price
    def getcurPrice(self):
        return(self.curPrice)
    def setcurPrice(self,price):
        self.curPrice = price
    def getChangePercent(self):
        x=self.curPrice-self.preClosingPrice
        y=x/self.curPrice
        return(y)
astock=Stock()
astock.oneStock(["10001","平头哥芯片",62.82,70.32])
print(astock.getStockSymbol())
print(astock.getStockName())
print(astock.getcurPrice())
print(astock.getpreClosingPrice())

class Stock():
    def __init__(self):
        self.__symbol = ""
        self.__name = ""
        self.preClosingPrice = 0
        self.curPrice = 0

    def oneStock(self, detailContent):
        self.__symbol = detailContent[0],
        self.__name = detailContent[1],
        self.preClosingPrice = detailContent[2],
        self.curPrice = detailContent[3],

    def getStockSymbol(self):
        return (self.__symbol)

    def getStockName(self):
        return (self.__name)

    def getpreClosingPrice(self):
        return (self.preClosingPrice)

    def setpreClosingPrice(self, price):
        self.preClosingPrice = price

    def getcurPrice(self):
        return (self.curPrice)

    def setcurPrice(self, price):
        self.curPrice = price

    def getChangePercent(self):
        x = self.curPrice - self.preClosingPrice
        y = x / self.curPrice
        return (y)


astock = Stock()
astock.oneStock(["10001", "平头哥芯片", 62.82, 70.32])
print(astock.getStockSymbol())
print(astock.getStockName())
# print(astock.getCurPrice()
print(astock.getcurPrice())
# print(astock.getPreClosingPrice())
print(astock.getpreClosingPrice())

img