Hide / random integer questions


def random_row(board):
   return randint(0, len(board) - 1)
def random_col(board):
    return randint(0, len(board) - 1)

why should we define a function first to return a random integer?
can I directly assign to it like below?
if we need 100 random integers, isn't it too troublesome to redo it again and again?

random_row = randint(0, len(board) - 1)
random_col = randint(0, len(board) - 1)

system returns that "NameError: name 'ranint' is not defined"


There is always more than one way to make the program work. However, the idea of the exercises is to combine what you have learned thus far in to a program, in this case the combination of lists and functions.

So far as the error, did you remember to import randint?

EDIT: Check the spelling.

'ranint' is not defined


thank you! i got it now.
i try again and it works! it does generate two random intergers:)


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