Python Loop to Find First Temperature Above 27

✅ *Python Scenario-Based Interview Question* 🧠 You have a list of temperatures: ``` temps = [23, 25, 24, 28, 26, 30, 22] ``` *Question:* *Find the first temperature above 27* using a simple loop. *Expected Output:* ``` 28 ``` *Python Code:* ``` for temp in temps: if temp > 27: print(temp) break ``` *Explanation:* - *Simple for loop* scans sequentially - *`break`* stops at first match - *Early termination* - doesn't check remaining elements - O(n) worst case, average O(k) where k is position 💬 *Tap ❤️ for more!*

To view or add a comment, sign in

Explore content categories