# Arup Guha
# Writing to a File - Basic Example
# 4/10/2020

# For checking if a file exists.
import os.path
from os import path

import random

if path.exists("multprobs.txt"):
    print("Sorry, the file we were going to write to exists. Exit program.")

# Safe to write to file.
else:

    # How we open a file to write to.
    # Very important - make sure this file doesn't exist in the directory
    # that your python program is in.
    myFile = open("multprobs.txt", "w")

    # Command to write to an output file is myFile.write(string)

    # 8 rows of problems
    for i in range(8):

        # 10 problems on a line. Each problem takes 3 lines to write out.
        for j in range(10):
            myFile.write("   "+str(random.randint(1,9))+"\t")
        myFile.write("\n")

        # On the second line I write a times sign.
        for j in range(10):
            myFile.write(" x "+str(random.randint(1,9))+"\t")
        myFile.write("\n")

        # On the third line I draw the horizontal line.
        for j in range(10):
            myFile.write("----"+"\t")
        myFile.write("\n")
        
        myFile.write("\n")
        myFile.write("\n")
        myFile.write("\n")

    # Close the file.
    myFile.close()
