1

My project is to code a program that mimics a simple percolation process.

When I run my program my output is a table with column headings as well.

How do I remove this? I only need my random numbers to appear.

import random
from prettytable import PrettyTable


def get_dimensions():
    return input("Enter the dimensions Ex:(5x5): ")


def validate(dim):
    if dim == "":
        dim = "5x5"
    try:
        rows = int(dim[0])
        columns = int(dim[2])
        if not (3 <= rows <= 100) or not (3 <= columns <= 100):
            print("The inputs of the dimensions MUST BE in the range of 3-9 inclusive.\nTry again!")
            return [True, 0, 0]
    except:
        print("The input format is not valid!\nPlease read the instructions and try again!\n")
        return [True, 0, 0]
    return [False, rows, columns]


def create_grid(rows, columns):
    numbers = list(range(10, 100)) + ["  "]
    main = [[random.choice(numbers) for k in range(columns)] for i in range(rows)]
    column_names = list(range(columns))
    table = PrettyTable(column_names)
    for row in main:
        table.add_row(row)
    print(table)
    return main


def check_percolation(main, columns):
    for i in range(columns):
        for row in main:
            if row[i] == "  ":
                print("  NO", end=" ")
                break
        else:
            print("  OK", end=" ")


def main():
    while True:
        dimension = get_dimensions()
        validation = validate(dimension)
        not_validated = validation[0]
        rows = validation[1]
        columns = validation[2]
        if not_validated:
            continue

        main = create_grid(rows, columns)
        check_percolation(main, columns)

        cont = input("\n\nDo you wish to continue? (Y/N): ")
        if cont.upper() == "N":
            break


main()

expected output

expected output

output I got

output i got

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158

1 Answers1

0

To hide column headings, put table.header = False before printing table in create_grid.

Style options:

[snip]

  • header - A boolean option (must be True or False). Controls whether the first row of the table is a header showing the names of all the fields. – https://pypi.org/project/prettytable/

Alternatively, change the print to

print(table.get_string(header=False))
Nathan Mills
  • 2,243
  • 2
  • 9
  • 15