Python - Variables and Dynamic TypingYou want to store a user's name and age, then print a greeting. Which code correctly uses variables for this?Aname == "Lily" age == 25 print("Hi " + name + ", you are " + age + " years old.")Bname = Lily age = 25 print("Hi " + name + ", you are " + age + " years old.")Cname = "Lily" age = 25 print("Hi " + name + ", you are " + str(age) + " years old.")Dname = "Lily" age = 25 print("Hi " + name + ", you are " + age + " years old.")Check Answer
Step-by-Step SolutionSolution:Step 1: Check variable assignmentsname = "Lily" age = 25 print("Hi " + name + ", you are " + str(age) + " years old.") assigns name as string and age as number correctly.Step 2: Check print statementname = "Lily" age = 25 print("Hi " + name + ", you are " + str(age) + " years old.") converts age to string for concatenation, avoiding errors.Final Answer:Correct variable assignment and print with conversion -> Option CQuick Check:Use = for assignment and convert numbers to strings [OK]Quick Trick: Convert numbers to strings before joining with text [OK]Common Mistakes:MISTAKESUsing == instead of =Not quoting stringsConcatenating number without conversion
Master "Variables and Dynamic Typing" in Python9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Python Quizzes Conditional Statements - Ternary conditional expression - Quiz 3easy For Loop - For–else execution behavior - Quiz 2easy Input and Output - Taking input using input() - Quiz 12easy Loop Control - Continue statement behavior - Quiz 11easy Loop Control - Continue statement behavior - Quiz 7medium Operators and Expression Evaluation - Identity operators (is, is not) - Quiz 2easy Python Basics and Execution Environment - Why Python is easy to learn - Quiz 10hard Variables and Dynamic Typing - Type checking using type() - Quiz 13medium While Loop - Counter-based while loop - Quiz 8hard While Loop - while True pattern - Quiz 10hard