Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lists topic python
#1
i been told to post it as new question in here. I am beginner on python and wanted some help to see if i am doing the right thing below and the next step to take with this thanks.

This is the question:

Create a simple list to hold the items 1,2,3,4, creating the list “from the front” as in Slide 48.[Notice how the list is only complete when you have finished.]Use the code from Slide 50 to print out your list. (You may want to write this as a function.)

class Node:
pass

start = Node()
point = start

point.data = 1
point.next = Node()
point = point.next

point.data = 2
point.next = Node()
point = point.next

point.data = 3
point.next = Node()
point = point.next

point.data = 4
point.next = None

def func1():
point = start
print(point.data)

point = point.next
print(point.data)

point = point.next

print(point.data)
point = point.next
print(point.data)
point = point.next
print("point:", point)

func1()
Also, did i assemble the code properly that i got from the slide 48 and 50(read question)
Reply
#2
Without access to the slides tough to tell, but this produces a linked list of objects, each object with a pointer to the next and containing a value in the attribute "data".
Reply
#3
and the slides are?
Reply
#4
The slides are 87 pages long and mostly talking about lists and looks more like walkthrough that doesn't make sense to me that much to be honest. if there is something specific for me to look for i can do that.
Reply
#5
unable to proceed without mentioned slides
Reply
#6
(Oct-14-2019, 08:06 PM)Larz60+ Wrote: unable to proceed without mentioned slides

Oh the mentioned slides 48 and 50 you mean? Thought you meant other slides. It had these code on them i just tried to put them together, the slide 48 was the Class Node one and the slide 50 was def funct1() whats below it , i just added function to open and closed for slide 50 or thats what i tried to do.
Reply
#7
So, is everything between def func1(): and the call to the function supposed to be indented so as to define the function?
Also, for your class, don't you need to indent "pass"?
Fixing the indentation your code works.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Program "Topic" 150 lines of code. sean1 3 2,431 Dec-25-2021, 05:49 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020