雨落为华 2021-06-15 23:49 采纳率: 25%
浏览 24

请问如何解决这个attribute error?

如题。就是照着教材上的代码敲的,实在是看不出来哪里不对,救救孩子::>_<::

from pythonds.basic.stack import Stack # As previously defined

r_stack = Stack()

def to_str(n, base):

    convert_string = "0123456789ABCDEF"

    while n > 0:

        if n < base:

            r_stack.push(convert_string[n])

        else:

            r_stack.push(convert_string[n % base])

        n = n // base

    res = ""

    while not r_stack.is_empty():

        res = res + str(r_stack.pop())

    return res

print(to_str(1489, 16))

 

AttributeError                            Traceback (most recent call last)

<ipython-input-17-00efae08601c> in <module>

     13         res = res + str(r_stack.pop())

     14     return res

---> 15 print(to_str(1453, 16))

 

<ipython-input-17-00efae08601c> in to_str(n, base)

     10         n = n // base

     11     res = ""

---> 12     while not r_stack.is_empty():

     13         res = res + str(r_stack.pop())

     14     return res

 

AttributeError: 'Stack' object has no attribute 'is_empty'

  • 写回答

1条回答 默认 最新

  • Python-ZZY 2023-01-23 19:37
    关注

    Stack类的代码附出来

    评论

报告相同问题?

悬赏问题

  • ¥15 苹果系统的mac m1芯片的笔记本使用ce修改器使用不了
  • ¥15 单相逆变的电压电流双闭环中进行低通滤波PID算法改进
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 如何卸载arcgis 10.1 data reviewer for desktop
  • ¥15 共享文件夹会话中为什么会有WORKGROUP
  • ¥15 关于#python#的问题:使用ATL02数据解算光子脚点的坐标(操作系统-windows)
  • ¥115 关于#python#的问题:未加密前两个软件都可以打开,加密后只有A软件可打开,B软件可以打开但读取不了数据
  • ¥15 在matlab中Application Compiler后的软件无法打开
  • ¥15 想问一下STM32创建工程模板时遇到得问题
  • ¥15 Fiddler抓包443