Hi!
My aim is to create a grid in which cols, rows, range, and step are given by the user BUT they have to be placed in the grid in a random way. Then, I have to save that grid in a txt file. I wrote the following using some inputs found around but I got stuck.
Essentially, I cannot combine random and step codes.
Thanks in advance for your help!
import random
import sys
import os.path
from numpy import *
from numpy.random import *
rows = input("Input the number of rows: ")
cols = input("Input the number of columns: ")
range_start = input("Specify the start of the range: ")
range_stop = input("Specify the stop of the range: ")
step = input("Specify the step: ")
def toAscii(name, body):
""" toAscii(nameString, headerList, body2DList) -> None """
# open a file
fname = name + ".txt"
print "Creating output ASCII file", fname,
f = open(fname,'w')
# create the body content
contentString = ""
for steP in body:
line = " ".join(str(col) for col in steP) + "\n"
contentString = contentString + line
# saving body
f.write(contentString)
f.close()
print "... Done!"
if __name__ == "__main__":
# test *****
#row = range(range_start, range_stop)
steP = range(range_start, range_stop, step)
print steP
print "the content to be saved:"
for line in steP:
print line
toAscii("user", steP)