

不知道為什么assert False pass不了
請教一下,這個assert False放在這里我該怎么改function?
uj5u.com熱心網友回復:
assert 斷言 這條陳述句完全可以洗掉。如果想得到全面的回答,請貼出全部代碼的文本。
uj5u.com熱心網友回復:
class Node:def __init__(self, value=https://bbs.csdn.net/topics/None, nextnode=None):
self.value = value
self.next = nextnode
def __repr__(self):
return '<Node ({})>'.format(repr(self.value))
def insert(head, value, position):
if position==0:
return Node(value,head)
else:
current_position = 1
node=head
try:
while node.next and current_position < position:
node = node.next
current_position += 1
node.next = Node(value,node.next)
except IndexError:
print('Should have failed with an IndexError')
return head
def pop(head, position):
if head is None:
return (None,None)
if position==0:
return (head,head.next)
node=head
current_position=1
if node.next and current_position<position:
node=node.next
current_position+=1
pop_value=https://bbs.csdn.net/topics/node.next
if pop_value.next is None:
return (node.next,head)
return (pop_value,head)
def stringify_linked_list(head):
if head is None:
return None
else:
node=head
list_=[]
while node:
list_.append(node)
node=node.next
stringlist=''
for i in list_:
stringlist+=str(i)+' -> '
stringlist=stringlist+'None'
return stringlist
uj5u.com熱心網友回復:
這是我的linked list,assert的是要test的代碼,我不知道該如何pass這個assertuj5u.com熱心網友回復:
請看我幫你修改的,去參考一下。
uj5u.com熱心網友回復:
非常感謝!!uj5u.com熱心網友回復:
別客氣。
1、你的代碼問題在于,自己寫的鏈表,沒有IndexError, 需要自定義例外。
2、測驗的斷言代碼,寫的地方不對。
uj5u.com熱心網友回復:
好的 謝謝!轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/133202.html
上一篇:python selenium chrome headless模式登錄網站求助
下一篇:縮短時間
