#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    22
    Rep Power
    0

    Is there a better way to construct this?


    lister=[]
    raw_input("Enter five names(press the enter key to start and after each name) :")
    for i in range(5):
    name=raw_input()
    lister.append(name)
    print "the names are: ", lister


    It runs, but when I put it into python tutor it doesnt work? Also When I run it and if I dont press enter and enter a name on the first prompt, it will not record it in the list. why is that? That is why i had to put the print statement to say push start before you start.

    Thanks
    -Dennis DEwitt
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,963
    Rep Power
    481
    "python tutor": unknown to me. You've used raw_input as a print statement which eats the first <Enter> character. In python2:
    Code:
    lister=[]
    print"Enter five names:",  ############## print statement ending in comma cancels the newline character print would otherwise append.
    for i in range(5):
      name=raw_input()
      lister.append(name)
    print "the names are: ", lister
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo