[Tutor] Question

Kwpolska kwpolska at gmail.com
Thu Aug 23 21:18:02 CEST 2012


On Thu, Aug 23, 2012 at 8:36 PM, Ashley Fowler
<afowler2 at broncos.uncfsu.edu> wrote:
>
> ________________________________________
> From: tutor-bounces+afowler2=broncos.uncfsu.edu at python.org [tutor-bounces+afowler2=broncos.uncfsu.edu at python.org] on behalf of Alan Gauld [alan.gauld at btinternet.com]
> Sent: Thursday, August 23, 2012 5:59 PM
> To: tutor at python.org
> 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  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

def printList(l):
    '\n'.join(l)

There.  Please take a look at my previous message.
-- 
Kwpolska <http://kwpolska.tk>
stop html mail      | always bottom-post
www.asciiribbon.org | www.netmeister.org/news/learn2quote.html
GPG KEY: 5EAAEA16


More information about the Tutor mailing list