Hello all,
I'm taking a intro computer science course, yet somehow I'm much better at c++ than python. My professor is essentially useless. Can anyone show me how to let these variables persist into global scope? I assumed declaring them globally would make them persist, yet it appears to not. Thank you.
(There are a few things that are irrelevant at this point-- just thinking ahead. Example is the strAlpha list)
# Riveter -- Justin M
strPlayer1 = ""
strPlayer2 = ""
nHeight = 0
nWidth = 0
strAlpha = "a b c d e f g h i j k l m n o p q r s t u v w x y z"
varBoard = 0
def Start():
print("Welcome to Riveter")
strPlayer1 = raw_input("Name of first player: ")
strPlayer2 = raw_input("Name of second player: ")
strInput = "not digits"
while not(strInput.isdigit()):
strInput = raw_input("How many rows should there be?: ")
nHeight = int(strInput)
strInput = "not digits"
while not(strInput.isdigit()):
strInput = raw_input("How many columns should there be? (Up to 26!): ")
nWidth = int(strInput)
def Setup():
nInsideLoop = 0
nOutsideLoop = 0
varBoard = [[0 for col in range(nWidth)] for row in range(nHeight)]
while nOutsideLoop < nHeight:
while nInsideLoop < nWidth:
if ((0 < nInsideLoop < nWidth) and (0 < nInsideLoop < nHeight)):
varBoard[nOutsideLoop][nInsideLoop] = 1
nInsideLoop = nInsideLoop + 1
nOutsideLoop = nOutsideLoop + 1
def Display():
nInsideLoop = 0
nOutsideLoop = 0
nHeight = 3
while nOutsideLoop < nHeight:
print "inside loop"
while nInsideLoop < nWidth:
if (varBoard[nOutsideLoop][nInsideLoop] == 0):
print "X"
if (varBoard[nOutsideLoop][nInsideLoop] == 1):
print " "
nInsideLoop = nInsideLoop + 1
nOutsideLoop = nOutsideLoop + 1
Start()
Setup()
print nWidth
print nHeight
Display()