如何迭代用户输入的链接值列表?

时间:2014-02-06 19:36:31

标签: python-2.7 linked-list

我正在尝试创建一个链接列表来存储用户输入的整数,然后迭代它们并将其打印出来,如何才能使其正常工作?

class linkedlist:
    def __init__(self,a,x):
        x= int(raw_input("Enter Number: "))
        self.a=[]

    def addusersinput():
        a.append(x)
        print a


    def removeitem():
        i=int(raw_input("Select number position: "))
        print "You can remove a number from this list by selecting it's poistion,/n the first number has a position of 0, 2nd number has a position of 1 and so on"
        a.pop(i)


class node:
    def __init__(self,c,value):
        self.c=i+1 #next node
        self.value=a[i+1]

    def show():
        print self.c
        print self.value

1 个答案:

答案 0 :(得分:0)

您不需要任何课程。如果这是家庭作业,请询问您的教授或助教是否需要帮助。

linked_list = []
inputs_to_record = 10
for input_number in range(inputs_to_record):
    user_input = raw_input("Enter a number:\n>")
    while not user_input.isdigit(): user_input = raw_input("Try again - must enter a number:\n>")
    linked_list.append(int(user_input))

for number in linked_list: print number
  

这是poistion

你拼错了位置,错误地使用了撇号。这是“它是”的收缩。你想要“它”,意思是“属于它。”