[{"id":"pythonintermediate-001","courseId":"python-intermediate","domain":"syntax-and-types","topic":"Short-circuit and/or return operands","prompt":"A function runs name = user_input or 'guest'. The user submits an empty string. What does name hold afterwards?","hint":"Look at which operand the operator returns, not only whether it is true.","explain":"Python's and and or give back one of their operands, not always True or False. Empty strings, zero, None and empty containers all count as false in a condition.","source":"https://docs.python.org/3/reference/expressions.html#boolean-operations","interaction":{"type":"single"},"options":[{"id":"a","text":"'guest', the right-hand operand","why":"The left side is false, so or skips it and returns the right side."},{"id":"b","text":"'' (the empty string)","whyNot":"An empty string is false, so or does not return it; it moves on to the right-hand side."},{"id":"c","text":"True, because or always gives a bool","whyNot":"or returns one of its operands unchanged, not a boolean, so the result is a string."},{"id":"d","text":"A TypeError, because or needs two booleans","whyNot":"or works on any objects; it does not require booleans on both sides."}],"answer":"a","explanation":"x or y returns x if x is true, otherwise y. x and y returns x if x is false, otherwise y. The result is an operand, not forced to True or False.","concept":"x or y returns x if x is true, otherwise y. x and y returns x if x is false, otherwise y. The result is an operand, not forced to True or False.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"user_input = ''\nname = user_input or 'guest'","takeaways":["'or' and 'and' return an operand; wrap the result in bool() when you need True or False."]},{"id":"pythonintermediate-002","courseId":"python-intermediate","domain":"syntax-and-types","topic":"Assignment expressions (:=)","prompt":"In Python 3.8 and later, the walrus operator := can only be used as a standalone statement, never inside a larger expression.","hint":"Think about what the operator was added to make possible.","explain":"A plain assignment is a statement, so it cannot sit inside another expression. Assignment expressions were added so a name can be bound and its value used within one expression.","source":"https://peps.python.org/pep-0572/","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"The walrus operator was added precisely so an assignment can sit inside an expression, such as a comprehension or an if test."},{"id":"b","text":"False","why":"Inside expressions like comprehensions and conditions, := binds a name and yields the value it assigned."}],"answer":"b","explanation":"NAME := expr is an assignment expression: it binds NAME and produces the value, so it can be used wherever an expression is allowed.","concept":"NAME := expr is an assignment expression: it binds NAME and produces the value, so it can be used wherever an expression is allowed.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Use := where you need a name inside an expression, such as a comprehension condition; keep = for plain assignments."]},{"id":"pythonintermediate-003","courseId":"python-intermediate","domain":"syntax-and-types","topic":"Ordering comparisons between incompatible types","prompt":"A developer evaluates these expressions in Python 3. Which TWO of them evaluate to True?","hint":"Check the comparison rule for each collection type separately.","explain":"Each built-in collection defines its own comparison rules. Sequences compare item by item, sets use subset tests, and equality also depends on type.","source":"https://docs.python.org/3/reference/expressions.html#value-comparisons","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"{1, 2} < {2, 3}","whyNot":"For sets, < means proper subset; neither set contains the other, so the result is False."},{"id":"b","text":"[1, 2] < [1, 2, 3]","why":"Lists compare item by item, and when one runs out first, the shorter list is ordered first."},{"id":"c","text":"[1, 2] == (1, 2)","whyNot":"Equal collections must also have the same type; a list is never equal to a tuple."},{"id":"d","text":"{1, 2} <= {1, 2, 3}","why":"<= on sets is a subset test, and every element of {1, 2} appears in {1, 2, 3}."},{"id":"e","text":"[1, 3] < [1, 2]","whyNot":"The first unequal items decide the order, and 3 is not less than 2."},{"id":"f","text":"{'a': 1} < {'a': 2}","whyNot":"Dicts do not support ordering, so < raises TypeError rather than returning True or False."}],"answer":"bd","explanation":"Lists compare item by item; sets use subset tests for < and <=; dicts raise TypeError on order comparisons; equal collections must be the same type.","concept":"Lists compare item by item; sets use subset tests for < and <=; dicts raise TypeError on order comparisons; equal collections must be the same type.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Lists order by first unequal item; sets order by subset; dicts raise TypeError on <, >, <= and >=."]},{"id":"pythonintermediate-004","courseId":"python-intermediate","domain":"syntax-and-types","topic":"Format spec mini-language","prompt":"A developer sets price = 3.14159 and prints it with an f-string. What appears on screen?","hint":"Focus on what the part after the colon controls.","explain":"The text after the colon in a replacement field is a format spec. It can set width, alignment, fill character and decimal precision, and the value is rendered to match it.","source":"https://docs.python.org/3/library/string.html#format-specification-mini-language","interaction":{"type":"single"},"options":[{"id":"a","text":"3.14","why":".2f asks for a fixed-point float with two decimal places, so the value is rounded to 3.14."},{"id":"b","text":"3.14159","whyNot":"Without a precision the full value would print, but the .2f spec limits it to two decimal places."},{"id":"c","text":"3.141","whyNot":"That keeps three decimal places; the spec asks for two."},{"id":"d","text":"3.15","whyNot":"The digit after the second decimal is 1, so rounding goes down to 3.14, not up."}],"answer":"a","explanation":"A format spec after ':' controls presentation. '.2f' formats a float as fixed-point with two decimal places, rounded.","concept":"A format spec after ':' controls presentation. '.2f' formats a float as fixed-point with two decimal places, rounded.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"price = 3.14159\nprint(f'{price:.2f}')","takeaways":["Format specs after ':' set width, alignment and precision; '.2f' rounds a float to two decimals."]},{"id":"pythonintermediate-005","courseId":"python-intermediate","domain":"syntax-and-types","topic":"Type hints not enforced at runtime","prompt":"Point2D is a TypedDict with x: int, y: int and label: str. Assigning {'x': 'one', 'y': 2, 'label': 'a'} to a Point2D variable raises a TypeError when that line runs.","hint":"Consider who checks a TypedDict's value types, and when.","explain":"Type annotations describe the shape of data, but the interpreter does not check them while the program runs. Separate tools called type checkers read them and report mismatches.","source":"https://docs.python.org/3/library/typing.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"A TypedDict instance is an ordinary dict at runtime, so the wrong value type is not rejected when the line runs."},{"id":"b","text":"False","why":"The value types are enforced only by a type checker; the assignment itself runs without error."}],"answer":"b","explanation":"TypedDict declares expected keys and value types, but only type checkers enforce them. At runtime a TypedDict instance is a plain dict.","concept":"TypedDict declares expected keys and value types, but only type checkers enforce them. At runtime a TypedDict instance is a plain dict.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Type hints, including TypedDict fields, are checked by type checkers, not by Python at runtime."]}]