________________________________________
From: [email protected]
[[email protected]] on behalf of Alan Gauld
[[email protected]]
Sent: Thursday, August 23, 2012 5:59 PM
To: [email protected]
Subject: Re: [Tutor] Question
On 23/08/12 18:02, Ashley Fowler wrote:
> def main():
> l = list()
> x = eval(input('Enter a number: '))
Don;t use eval() its bad practicecand fort advanced use only.
Instead explicitly convert to int() or float()
> while x >= 0:
> l.append(x)
> x = eval(input('Enter a number: '))
Same here.
> ask = input (" Do you want to perform a list operation?")
> if "yes":
You need to test if ask is equal to 'yes'
Testing 'yes' directly will always be true because 'yes' always exists.
> input (" Do you want to test, peek, add, or remove?")
you need to store the reurn value from input as you did above
> if "test":
and use that stored value in the test.
> if not l:
> print("The list is not empty")
> else:
> print("The list is empty")
HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
______________________________________________________________________________________________________________________
REPLY:
Thank you I finally fixed it. Can anyone break down how to do the next step
which is:
"You also need to write a function "printList" of one parameter that
takes a list as its input and neatly prints the entire contents of the
list in a column."
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor