dfssdfdsdfd 2021-11-20 10:38 采纳率: 97.6%
浏览 19
已结题

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())




  • 写回答

3条回答 默认 最新

  • 风铃扬音 2021-11-20 11:03
    关注
     
    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())
    
    # 定义函数不能嵌套定义,
    #缩进问题
    #最后两行调用函数的函数名大小写有误。
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 11月28日
  • 已采纳回答 11月20日
  • 创建了问题 11月20日

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址