0

I'm writing a simple program that is basically a signup program for a run. I am very new to python, but cant seem to find out why this isn't working. My error message is saying something is wrong with line 9. I would really appreciate if someone could help me work this out. I have been looking around for ages trying to find solutions, it's probably a very easy mistake.

Cheers!!

    allnames = []
    allages = []
    allgenders = []
    alltimes = []
    allhouses = []
    more = "yes"
    print "---- RUN ----"
    while (more) == "yes":
      runnername = input("Input runner name:")
      allnames.append(runnername)
      print str(allnames)

Thanks for all the help! Got it now. It's for NAT 5 Computing so i'm very new and inexperienced. Appreciate everyones answers!!

lmxx
  • 21
  • 1
  • If you are using Python2 (and from the looks of it you are because print wouldn't work without parenthesis) then you want `raw_input`, not `input`. – sberry Oct 07 '17 at 16:45
  • @AntonvBR you're a lifesaver! I knew it would be something easy. Care to help a poor man out? What exactly does raw input do differently from just input? Cheers!! – lmxx Oct 07 '17 at 16:46
  • @lmxx How about google it? :) Here is what I found: Read more here: https://stackoverflow.com/questions/4915361/whats-the-difference-between-raw-input-and-input-in-python3-x – Anton vBR Oct 07 '17 at 16:46
  • Or just search this site: https://stackoverflow.com/questions/4915361/whats-the-difference-between-raw-input-and-input-in-python3-x – sberry Oct 07 '17 at 16:48
  • 2
    Possible duplicate of [input() error - NameError: name '...' is not defined](https://stackoverflow.com/questions/21122540/input-error-nameerror-name-is-not-defined) – Tadhg McDonald-Jensen Oct 07 '17 at 16:48
  • `input` basically calls [eval](https://docs.python.org/2/library/functions.html#eval) on whatever the user inputs. Don't use it. – roganjosh Oct 07 '17 at 16:49

5 Answers5

1

Use this:

while (more == "yes"):

instead of :

while (more) == "yes":

and it should work fine.

Avik Aggarwal
  • 599
  • 7
  • 28
1

Change:

input() to raw_input()

Read more here: What's the difference between raw_input() and input() in python3.x?

Anton vBR
  • 18,287
  • 5
  • 40
  • 46
1

You're in an infinite loop. Try this:

allnames = []
more = "yes"

print "---- RUN ----"

while more == "yes":
      runnername = raw_input("Input runner's name: ")
      allnames.append(runnername)
      if len(allnames) == 5:
          more = "no"

print allnames

Change the condition in if len(allnames) == 5 according to your requirement.

srikavineehari
  • 2,502
  • 1
  • 11
  • 21
1

in this code you have looking ages also. In your code you miss the '()' bracket in print statment and also miss secound time run statment for ages.

allnames = []
allages = []
allgenders = []
alltimes = []
allhouses = []
more = "yes"
print("---- RUN ----")
while (more) == "yes":
    runnername = input("Input runner name:")
    allnames.append(runnername)
    print(str(allnames))

    runnerages = input("Input runner ages:")
    allages.append(runnerages)
    print(str(allages))
Shubh Patel
  • 87
  • 1
  • 6
0

You are getting error beacuse of input(). Replace it with raw_input() for python2.X .

Then try this way :

allnames = []
allages = []
allgenders = []
alltimes = []
allhouses = []
more = "yes"
print "---- RUN ----"
while (more) == "yes":
  runnername = raw_input("Input runner name:")
  allnames.append(runnername)
  print str(allnames)

N.B: python2.X

Md. Rezwanul Haque
  • 2,882
  • 7
  • 28
  • 45