[Tutor] Question
Ashley Fowler
afowler2 at broncos.uncfsu.edu
Tue Sep 11 18:08:11 CEST 2012
I have a question. In a assignment it asks for me to do the following below...
if "peek" then print the Student object at the beginning
of the list (using __str__) but don't remove it from
the list;
Could you explain what it means?
This is what I have so far,
elif ask == "peek":
print("First Name In List =", names[0])
How would you make it a string?
I know have a example of it but I'm not sure how to apply it to my code...The example is below.
def __str__(self):
return self.sides + "\t" + self.value
Also below is part of the assignment and my whole code is in the attachment.
A "main" function which does the following:
(1) create an empty list;
(2) ask the user if he/she wants to perform a list operation.
if "yes":
(a) prompt the user for the operation:
"test", "peek", "add", or "remove";
(b) perform the operation:
(i) if "test" then print whether the list is empty or not;
(ii) if "peek" then print the Student object at the beginning
of the list (using __str__) but don't remove it from
the list;
(iii) if "add", then prompt the user for student info, make
a Student object containing that info, and
add that Student object to the end of the list;
(iv) if "remove", then delete the Student object at the
beginning of the list and print it using __str__;
repeat step (2) until the user enters "no";
(3) neatly print the entire list from beginning to end.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120911/951b5e32/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: StudentTester.py
Type: application/octet-stream
Size: 960 bytes
Desc: StudentTester.py
URL: <http://mail.python.org/pipermail/tutor/attachments/20120911/951b5e32/attachment.obj>
More information about the Tutor
mailing list