Bird
0
0

You want to store a user's name and age, then print a greeting. Which code correctly uses variables for this?

hard📝 Application Q8 of 15
Python - Variables and Dynamic Typing
You 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.")
Step-by-Step Solution
Solution:
  1. Step 1: Check variable assignments

    name = "Lily" age = 25 print("Hi " + name + ", you are " + str(age) + " years old.") assigns name as string and age as number correctly.
  2. Step 2: Check print statement

    name = "Lily" age = 25 print("Hi " + name + ", you are " + str(age) + " years old.") converts age to string for concatenation, avoiding errors.
  3. Final Answer:

    Correct variable assignment and print with conversion -> Option C
  4. Quick Check:

    Use = for assignment and convert numbers to strings [OK]
Quick Trick: Convert numbers to strings before joining with text [OK]
Common Mistakes:
MISTAKES
  • Using == instead of =
  • Not quoting strings
  • Concatenating number without conversion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes