############################################################ # COMPUTER SCIENCE UNDERGRADUATE SCHOLARSHIP EXAM # UNIVERSITY OF WAIKATO # PYTHON PROGRAMMING LANGUAGE # JULIANO TAVARES (TAURANGA BOYS' COLLEGE YR 13) ############################################################ # Import modules import sys # Welcome user print("Welcome to Visualising Graphs") # Build the backend of the grid for the graph def main(): graph_grid = [[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], ] # Set variables max_x = 8 max_y = 24 # Set scale for the graph grid (list) scale = [4, 3, 2, 1, 0, -1, -2, -3, -4] # Draw the grid for the graph graph_grid = [[" " for col in range(max_y + 1)] for row in range(max_x + 1)] # Draw the vertical line on the first column for col in range(max_y + 1): graph_grid[4][col] = "_" # Draw the horizontal line on the last row for row in range(max_x + 1): graph_grid[row][0] = "|" # Draw x's on y(2) for col in range(1, max_x + 1): graph_grid[2][col] = "x" # Draw y's on x(4) for row in range(1, max_x + 1): graph_grid[row][3] = "x" # Showing the scale on the side of the grid for row, scale_value in zip(graph_grid, scale): # Convert each item in row to a string and join them print(f"{scale_value:<5}{''.join(str(item) for item in row)}")