You want to create a simple Python program that asks for your name and then greets you. Which code correctly does this?
hard📝 Application Q15 of 15
Python - Basics and Execution Environment
You want to create a simple Python program that asks for your name and then greets you. Which code correctly does this?
Ainput('Enter your name: ')
print('Hello, {name}!')
Bprint('Enter your name: ')
name = input
print('Hello, name!')
Cname = input('Enter your name: ')
print('Hello, name!')
Dname = input('Enter your name: ')
print(f'Hello, {name}!')
Step-by-Step Solution
Solution:
Step 1: Use input() to get user input and f-string to greet
name = input('Enter your name: ')
print(f'Hello, {name}!') correctly assigns the input to variable name and uses f-string print(f'Hello, {name}!') to show the greeting with the actual name.
Final Answer:
name = input('Enter your name: ')
print(f'Hello, {name}!') -> Option D
Quick Check:
input() + f-string greet = correct [OK]
Quick Trick:Use input() to get text, f-string to show it [OK]
Common Mistakes:
MISTAKES
Not assigning input to a variable
Printing variable name as text instead of value
Missing parentheses in input or print
Master "Basics and Execution Environment" in Python
9 interactive learning modes - each teaches the same concept differently