from RPi import GPIO

GPIO.setmode(GPIO.BCM)

num_pins = 28

pins = range(num_pins)

for pin in pins:
    GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP)

pin_states = {pin: GPIO.input(pin) for pin in pins}

print()
for pin, state in pin_states.items():
    print("%2d: %s" % (pin, state))

active = sum(pin_states.values())
inactive = num_pins - active

print()
print("Total active: %i" % inactive)
print("Total inactive: %i" % active)

from RPi import GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

num_pins = 28

pins = range(num_pins)

for pin in pins:
    GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP)

pin_states = {pin: GPIO.input(pin) for pin in pins}

print()
for pin, state in pin_states.items():
    print("%2d: %s" % (pin, state))

active = [pin for pin, state in pin_states.items() if not state]
inactive = [pin for pin, state in pin_states.items() if state]

print()
print("Total active: %s" % len(active))
print("Total inactive: %s" % len(inactive))
print()
print("Active pins: %s" % str(active))
print("Inactive pins: %s" % str(inactive))


Add printing of active/inactive pins
Add printing of active/inactive pins

  from RPi import GPIO
  
  GPIO.setmode(GPIO.BCM)
+ GPIO.setwarnings(False)
  
  num_pins = 28
  
  pins = range(num_pins)
  
  for pin in pins:
      GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP)
  
  pin_states = {pin: GPIO.input(pin) for pin in pins}
  
  print()
  for pin, state in pin_states.items():
      print("%2d: %s" % (pin, state))
  
- active = sum(pin_states.values())
- inactive = num_pins - active
+ active = [pin for pin, state in pin_states.items() if not state]
+ inactive = [pin for pin, state in pin_states.items() if state]
  
  print()
- print("Total active: %i" % inactive)
+ print("Total active: %s" % len(active))
- print("Total inactive: %i" % active)
+ print("Total inactive: %s" % len(inactive))
+ print()
+ print("Active pins: %s" % str(active))
+ print("Inactive pins: %s" % str(inactive))
  
+ 
Add printing of active/inactive pins
## Code Before:
from RPi import GPIO

GPIO.setmode(GPIO.BCM)

num_pins = 28

pins = range(num_pins)

for pin in pins:
    GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP)

pin_states = {pin: GPIO.input(pin) for pin in pins}

print()
for pin, state in pin_states.items():
    print("%2d: %s" % (pin, state))

active = sum(pin_states.values())
inactive = num_pins - active

print()
print("Total active: %i" % inactive)
print("Total inactive: %i" % active)

## Instruction:
Add printing of active/inactive pins
## Code After:
from RPi import GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

num_pins = 28

pins = range(num_pins)

for pin in pins:
    GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP)

pin_states = {pin: GPIO.input(pin) for pin in pins}

print()
for pin, state in pin_states.items():
    print("%2d: %s" % (pin, state))

active = [pin for pin, state in pin_states.items() if not state]
inactive = [pin for pin, state in pin_states.items() if state]

print()
print("Total active: %s" % len(active))
print("Total inactive: %s" % len(inactive))
print()
print("Active pins: %s" % str(active))
print("Inactive pins: %s" % str(inactive))

