Use if statement to check zero
op = 0 if !op.zero? # not a zero? puts 12 / op else puts "Can't divide by zero." end op = 2 if op.nonzero? # is it nonzero? puts 12 / op else puts "Can't divide by zero." end