# Author:  James Tam
# Version: November 19, 2021
# Learning objectives:
# * Creating a 2D tuple
# * Accessing different parts of a tuple: row, elements in a row/column
# * How tuples are immutable

def start():
    #Start of period table
    print("Printing table row-by-row using a for-loop")
    periodic = (("H, 1.008", "He, 4.0026"),
                ("Li, 6.94", "B, 10.81", "C, 12.011", "N, 14.007", "O, 15.999", "F, 18.998", "Ne, 20.180"))   
    for row in periodic:
        print(row) #A row = tuple
    print("- - - - ")

    r = 0
    numRows = len(periodic)
    print("Printing table row-by-row using a while-loop")
    while (r < numRows):
        print(periodic[r])
        r = r + 1
    print("- - - - ")

    r = 0
    numRows = len(periodic)
    print("Printing table element-by-element using nested while-loops")
    while (r < numRows):
        e = 0
        numElements = len(periodic[r]) #Number elements in a particular row
        while (e < numElements):
            print("%s" %(periodic[r][e]), end=": ")
            e = e + 1
        print()
        r = r + 1
    print("- - - - ")

    copyPeriodic = periodic #Both refer to sample tuple
    periodic = (1, 2 , 3,"Go!") #New tuple created, original isn't changed

    print("Original")
    print(copyPeriodic)
    print("New")
    print(periodic)
    print("- - - - ")

    print("Cannot force original to change (immutable type), about to crash")
    #periodic[2] = "Stop"


start()
