Python - Basics and Execution EnvironmentWhich of the following code snippets will cause an IndentationError in Python?Adef greet(): print('Hello') print('Welcome')Bfor i in range(3): print(i) print('Done')Cif true: print('Yes')Dwhile false: passCheck Answer
Step-by-Step SolutionSolution:Step 1: Review indentation consistencyPython requires all statements in the same block to have the same indentation level.Step 2: Identify inconsistent indentationfor i in range(3): print(i) print('Done') has the second print statement less indented than the first inside the for loop, causing an error.Final Answer:for i in range(3):\n print(i)\n print('Done') -> Option BQuick Check:Inconsistent indentation = IndentationError [OK]Quick Trick: All lines in a block must align equally [OK]Common Mistakes:MISTAKESMixing tabs and spacesIndenting some lines less than others in a blockForgetting to indent after a colon
Master "Basics and Execution Environment" in Python9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Python Quizzes Conditional Statements - Nested conditional execution - Quiz 4medium Data Types as Values - String values and text handling - Quiz 15hard For Loop - Iterating over lists - Quiz 12easy For Loop - Iterating over strings - Quiz 14medium For Loop - Why loops are needed - Quiz 15hard Input and Output - print() parameters and formatting - Quiz 15hard Operators and Expression Evaluation - Comparison operators - Quiz 5medium Variables and Dynamic Typing - Variable assignment in Python - Quiz 8hard Variables and Dynamic Typing - Variable assignment in Python - Quiz 13medium While Loop - Why while loop is needed - Quiz 14medium