- #1
mr.me
- 49
- 0
This isn't exactly part of my homework but I wanted to know how I could save the output of this program to txt file?
The program was my homework and it was to allow the user to enter the starting values for a multiplication tables columns and rows and print a 10x10table
I did it like so..
Is there a way I could save the printed values to a file?
The program was my homework and it was to allow the user to enter the starting values for a multiplication tables columns and rows and print a 10x10table
I did it like so..
Code:
print "To create a '10x10' multiplication table: "
row = int(raw_input("Enter the first row number: " ))
col = int(raw_input("Enter the frist column number: "))
lastRow = row + 10 # These lines assign the value of the variables
firstRow=col
lastCol = col + 10
print " ",
while (col<lastCol): # loop from col to col + 10
print "%3d" % col, #each iteration prints the column header value.
col+=1
print "\n","-"*50,
col=firstRow #reset col values
#end loop
print #moves to the next line
while (row < lastRow): #This line creates the conditions in which both loops operate
print row,"|", #Prints a header for each row
while(col < lastCol): #This line creates the conditions for the inner loop
print "%3d" %(col * row),
col +=1
col=firstRow #This line updates the value for which "col"
row +=1 #This line updates the value for "row"
print
Is there a way I could save the printed values to a file?