Bird
0
0

Given the code snippet below, what will be the printed output?

medium📝 Predict Output Q5 of 15
Raspberry Pi - PWM Output
Given the code snippet below, what will be the printed output? import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(22, GPIO.OUT) pwm = GPIO.PWM(22, 50) pwm.start(2.5) print('Started PWM with duty cycle:', 2.5) pwm.ChangeDutyCycle(12.5) print('Changed duty cycle to:', 12.5) pwm.stop() GPIO.cleanup()
ANo output printed
BStarted PWM with duty cycle: 2.5 Changed duty cycle to: 12.5
CError: GPIO not set up correctly
DStarted PWM with duty cycle: 12.5 Changed duty cycle to: 2.5
Step-by-Step Solution
Solution:
  1. Step 1: Analyze print statements

    The code prints the duty cycle values immediately after starting and changing PWM.
  2. Step 2: Confirm order of prints

    First print shows 2.5, second print shows 12.5 as per ChangeDutyCycle call.
  3. Final Answer:

    Started PWM with duty cycle: 2.5 Changed duty cycle to: 12.5 -> Option B
  4. Quick Check:

    Print statements match duty cycle changes [OK]
Quick Trick: Print outputs match duty cycle calls in order [OK]
Common Mistakes:
  • Mixing print order
  • Assuming runtime error
  • Ignoring print statements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes