import NDIR
import time

sensor = NDIR.Sensor(0x4D)
sensor.begin()

while True:
    sensor.measure()
    print("CO2 Concentration: " + str(sensor.ppm) + "ppm")
    time.sleep(1)

import NDIR
import time

sensor = NDIR.Sensor(0x4D)

if sensor.begin() == False:
    print("Adaptor initialization FAILED!")
    exit()

while True:
    if sensor.measure():
        print("CO2 Concentration: " + str(sensor.ppm) + "ppm")
    else:
        print("Sensor communication ERROR.")

    time.sleep(1)

Make use of the return value of begin() and measure()
Make use of the return value of begin() and measure()
  import NDIR
  import time
  
  sensor = NDIR.Sensor(0x4D)
- sensor.begin()
+ 
+ if sensor.begin() == False:
+     print("Adaptor initialization FAILED!")
+     exit()
  
  while True:
-     sensor.measure()
+     if sensor.measure():
-     print("CO2 Concentration: " + str(sensor.ppm) + "ppm")
+         print("CO2 Concentration: " + str(sensor.ppm) + "ppm")
+     else:
+         print("Sensor communication ERROR.")
+ 
      time.sleep(1)
  
Make use of the return value of begin() and measure()
## Code Before:
import NDIR
import time

sensor = NDIR.Sensor(0x4D)
sensor.begin()

while True:
    sensor.measure()
    print("CO2 Concentration: " + str(sensor.ppm) + "ppm")
    time.sleep(1)

## Instruction:
Make use of the return value of begin() and measure()
## Code After:
import NDIR
import time

sensor = NDIR.Sensor(0x4D)

if sensor.begin() == False:
    print("Adaptor initialization FAILED!")
    exit()

while True:
    if sensor.measure():
        print("CO2 Concentration: " + str(sensor.ppm) + "ppm")
    else:
        print("Sensor communication ERROR.")

    time.sleep(1)
