NEERAJ KANT
CODING / BEGINNER
The task is simple: ask for a name, store the reply, and display a greeting. Read this code before running it:
name = input("What is your name? ")
print("Hello,", name)
print("Welcome to Python!")input() displays a prompt and returns the text entered by the user. The variable name stores that text. print() displays output. The quotation marks identify text written directly in the program.
First, predict the output if the user enters Asha. Then run the program and compare the result with your prediction. Finally, explain each line aloud or to a partner. This makes it easier to notice whether you understand the code or have only copied it.
Try a fictional name, then a name with a space. What changes? The program stores the whole line of text that the user enters.
At this stage, a number entered through input() is still text. If you want to calculate with it, convert it first using int() for an integer or float() for a decimal. Entering unsuitable text during conversion produces an error.
Can you identify the input, the variable, and the output? Can you explain why name has no quotation marks when it is used as a variable? If something fails, check spelling, matching quotation marks, and parentheses one at a time.
Next, try the rectangle exercise on the Resources page. It adds arithmetic to the same input–process–output pattern.