-1

Working on a project for my Stats class and I've hit a roadblock...

I need to convert this code, given by the professor...

# Set seed if required and determine if seed is not an integer  
#   
       if(!is.null(seed)) {   
              if(is.integer(seed)) set.seed(seed)   
              else stop("Non NULL or Integer Seed") 
       }

...into Python. I thought i got it right, but I'm coming up short with this expression.

 if seed != None :   
              if is_integer(seed) :
              rd.seed(seed)  
                  return
              else :
                  sys.exit("Non NULL or Integer Seed") 

It gives me a "IndentationError: expected an indented block". Can you seed in Python without immediately following it with random.randint()?

Jack Karrde
  • 121
  • 1
  • 5

2 Answers2

1

The indentation problem is at rd.seed(seed) line:

if seed != None:   
    if is_integer(seed):
      rd.seed(seed)  
      return
else:
  sys.exit("Non NULL or Integer Seed")
Francesco Grossetti
  • 1,555
  • 9
  • 17
0

Be careful with the identations! Your code should be look like this:

if seed != None:   
    if is_integer(seed):
        rd.seed(seed)  
        return
else:
    sys.exit("Non NULL or Integer Seed")
matebende
  • 543
  • 1
  • 7
  • 21