'Extremely Basic Python arrays and variable code not working

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!!



Solution 1:[1]

Use this:

while (more == "yes"):

instead of :

while (more) == "yes":

and it should work fine.

Solution 2:[2]

Change:

input() to raw_input()

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

Solution 3:[3]

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.

Solution 4:[4]

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))

Solution 5:[5]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Avik Aggarwal
Solution 2 Anton vBR
Solution 3
Solution 4 Shubh Patel
Solution 5 Md. Rezwanul Haque