Bird
0
0

Given this Python code reading GPS data: import serial ser = serial.Serial('/dev/serial0', 9600, timeout=1) line = ser.readline().decode('ascii', errors='replace') print(line.strip()) If the GPS sends the sentence '$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47', what will be printed?

medium📝 Predict Output Q4 of 15
Raspberry Pi - Serial UART Communication
Given this Python code reading GPS data: import serial ser = serial.Serial('/dev/serial0', 9600, timeout=1) line = ser.readline().decode('ascii', errors='replace') print(line.strip()) If the GPS sends the sentence '$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47', what will be printed?
AGPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
B$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
CError decoding line
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Understand readline and decode

    ser.readline() reads one line including the newline; decode converts bytes to string.
  2. Step 2: Apply strip()

    strip() removes whitespace including newline but not internal characters, so the full sentence remains.
  3. Final Answer:

    $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47 -> Option B
  4. Quick Check:

    Output line = full NMEA sentence [OK]
Quick Trick: strip() removes whitespace, not sentence content [OK]
Common Mistakes:
MISTAKES
  • Assuming $ is removed
  • Expecting decoding error
  • Confusing strip with replace

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes