0

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.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by pyTony
0

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

Edited by pyTony: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.