For statement


#1

from random import randint

board =[]

for x in range(5):
board.append([“0”]*5)

def x(board):
for x in board:
print " ".join(x)

x(board)

def realcol(board):
return randint(0,len(board)-1)
def realrow(board):
return randint(0,len(board)-1)

print realcol(board)
print realrow(board)

(x = realcol(board)
y = realrow(board)
print x
print y
when i assign a variable for them it worked as expected but if i code like the ones above it keep giving the output’miss’)(these words are not written in the code i’m currently running)

guesscol =int(raw_input(‘input1:’))

guessrow =int(raw_input(‘input2:’))

if guesscol == x and guessrow == y:
print ‘nice’
else:
board[guesscol][guessrow] = ‘x’
print’miss’

i couldn’t understand why i need to assign a variable for the random numbers to make my guessing input match with the random answer the code above shown


#2

Does not store anything.

is necessary to store the values for later comparison.


#3

I see now i understand.Thanks!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.