I need to take the element from a list and use them as the input for the rest of my script.
Right now I have it set up with a raw_input and I have to enter numbers in sequence and the script runs. I would like the computer to do this. Is there a way?
e.g.
This is in the terminal
& Enter number: 1
& Enter number: 2

I enter the number it runs the rest of my script then loops back for the next input. Is there a way to create a list of numbers say from 1 to 20 and then put each one in as an input for the script to run. Basically I want to automate it so I dont have enter the numbers.

Here is one way, as input mus be strings in multiple lines we go little roundabout:

import sys,cStringIO
inputs=[str(i) for i in range(20)]
sys.stdin=cStringIO.StringIO('\n'.join(inputs))

for i in range(20):
    print int(raw_input('Enter number: '))*i
"" Output:
Enter number: 0
Enter number: 1
Enter number: 4
Enter number: 9
Enter number: 16
Enter number: 25
Enter number: 36
Enter number: 49
Enter number: 64
Enter number: 81
Enter number: 100
Enter number: 121
Enter number: 144
Enter number: 169
Enter number: 196
Enter number: 225
Enter number: 256
Enter number: 289
Enter number: 324
Enter number: 361
>>> """
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.