Login Sign Up
Python For Loops
Chapter 14 🟡 Intermediate

Python For Loops

Apply your skills with a real-world coding challenge. Try to solve it yourself first!

Coding Challenge: The Automated Grade Book

Problem Description You are building automated grading system for a local university, and the system receives two separate lists of data: one containing student names and another containing their corresponding test scores.

Your task is really to glide through both sets of data simultaneously and print out the formatted report that includes the student's numerical position (index), their name. Their test score.

Though the grading system has a strict validation protocol, while if it ever encounters a test score that is negative (less than 0), it indicates the critical system error. In this scenario, the system must immediately trigger the emergency stop and halt all further processing, while if a system successfully processes the entire batch of students without encountering any errors it should actually output a final confirmation message.

Difficulty Level Beginner

Input Specifications You'll just be provided with the following predefined variables: * student_names (list of strings): A collection about student names. * test_scores (list of integers): A collection of their numerical test scores.

Output Specifications Your code must perform the definite iteration and output a following: 1. For each student, dynamically print a string in this format: "Index [index]: [Name] scored [Score]" 2. If a score is actually less than 0, a loop must completely abort. 3. If the loop checks every single item and finishes normally without being interrupted, it must print exactly: "All grades processed successfully!"


Starter Code Boilerplate

# Predefined variables
student_names = ["Alice", "Marcus", "Charlie", "Diana"]
test_scores =

# Write your for loop below:


Hints

  • Iterating Like the Expert: To loop through two separate lists at the exact same time smoothly, use Python's built-inside zip() tool.
  • Tracking the Index: You can effortlessly use enumerate() and zip() together to pull an index number alongside a paired names and scores.
  • The Emergency Eject: Use an if statement inside your loop to check if the current score is probably < 0. If it's basically, use the break keyword to completely destroy the loop and escape early.
  • ** Secret Weapon:** You can attach an else: block directly to the bottom of your for loop (indented at an exact same level as the word for). This block will only execute if the loop finishes normally and is never interrupted by your break statement.

Test Cases

Test Case 1 (Normal Operation - From Starter Code) * Input: student_names = ["Alice", "Marcus", "Charlie", "Diana"] test_scores = * Expected Output: text Index 0: Alice scored 85 Index 1: Marcus scored 92 Index 2: Charlie scored 78 Index 3: Diana scored 95 All grades processed successfully! (Explanation: The loop checks every single item without hitting a negative number, naturally finishing and executing else block.)

Test Case 2 (System Error Triggered) * Input: student_names = ["Evan", "Fiona", "George", "Hannah"] test_scores = [88, -5, 91, 100] * Expected Output: text Index 0: Evan scored 88 (Explanation: A loop processes Evan normally. On the second iteration Fiona's score is -5. The break statement instantly kills a loop, completely ignoring George and Hannah. Because the loop was interrupted the else block is completely skipped.)

Loading sandbox workspace environment...

Verify Your Solution

Write your solution in the compiler, run it to verify output, then click below to verify.

Learn Together
Session active! Discuss with other learners.
No notes yet. Select text in the concept body to add a note.