nerdexam
Python_Institute

PCEP-30-02 · Question #277

You want the name the user puts in to be written back to the monitor. What snippet would you insert in the line indicated below: print('Enter Your Name: ') insert your code here print(name)

The correct answer is C. name = input('name'). Option C is correct because name = input('name') does two essential things: it calls input() with a prompt string (displaying name to the monitor as a cue), and it assigns the user's typed response to the variable name, which the following print(name) can then display. Why the…

Question

You want the name the user puts in to be written back to the monitor. What snippet would you insert in the line indicated below: print('Enter Your Name: ')

insert your code here

print(name)

Options

  • Ainput(name)
  • Bname = input()
  • Cname = input('name')
  • Dinput('name')

How the community answered

(38 responses)
  • A
    18% (7)
  • B
    3% (1)
  • C
    71% (27)
  • D
    8% (3)

Explanation

Option C is correct because name = input('name') does two essential things: it calls input() with a prompt string (displaying name to the monitor as a cue), and it assigns the user's typed response to the variable name, which the following print(name) can then display.

Why the distractors fail:

  • A (input(name)) - name hasn't been defined yet, so Python raises a NameError; it also discards whatever the user types since there's no assignment.
  • B (name = input()) - correctly assigns to name, but passes no prompt string to input(), which the exam considers incomplete usage of the function's signature (even though the preceding print already prompted the user).
  • D (input('name')) - shows a prompt but throws away the return value with no assignment, so print(name) would still crash with a NameError.

Memory tip: Think of input() as a vending machine - you put a message in (the prompt string), the user puts their answer in, and you must catch what comes out with =. No = means the value falls on the floor.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice