PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A program prints a greeting: name = input("Enter name: "); print("Hello, " + name + "!"). If user enters "Alice", what is output?
⚠ Common exam trap
Python Institute often tests whether candidates notice the exact placement of spaces and punctuation in string literals, exploiting the common assumption that Python automatically adds spaces around concatenated values.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Hello, Alice!
The `print` function concatenates the string literals and the variable `name` using the `+` operator exactly as specified. When the user enters "Alice", the expression `"Hello, " + name + "!"` becomes `"Hello, Alice!"` — the space after the comma is part of the first string literal, and the exclamation mark is part of the last string literal, producing the output exactly as shown in option A.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Hello, Alice!
Why this is correct
Correct; exact concatenation.
- ✗
Hello,Alice !
Why it's wrong here
Missing space and extra space.
- ✗
Hello,Alice!
Why it's wrong here
Missing space after comma.
- ✗
Hello, Alice !
Why it's wrong here
Extra space before exclamation.
Go deeper
Related to this question
About these practice questions
One of 498 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
Same concept, more angles
3 more ways this is tested on PCEP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. What is the output of the following code? def greet(name, greeting='Hello'): print(greeting, name) greet('Alice')
easy- A.Hello
- ✓ B.Hello Alice
- C.SyntaxError
- D.Alice
Why B: The function `greet` has a default parameter `greeting='Hello'`. When called with only one argument (`'Alice'`), the default value is used for `greeting`, so the output is `Hello Alice`. The `print` function outputs both arguments separated by a space.
Variation 2. Given the code: ```python name = input('Enter your name: ') print('Hello, ' + name) ``` If the user enters 'Alice', what is the output?
medium- A.Hello,Alice
- B.Hello, 'Alice'
- ✓ C.Hello, Alice
- D.Hello, Alice
Why C: The `print('Hello, ' + name)` statement concatenates the string literal `'Hello, '` (which includes a trailing space) with the user input `'Alice'`, producing the output `Hello, Alice`. The `input()` function returns the exact string entered by the user without any extra quotes or formatting.
Variation 3. Refer to the exhibit. The code used is: name = input('Enter name: '); print('Hello', name). What will be printed if the user enters 'Alice'?
hard- A.Hello Bob
- B.Error
- ✓ C.Hello Alice
- D.Hello name
Why C: The `input()` function captures the user's typed input as a string, and the `print()` function outputs the string 'Hello ' followed by the value of the `name` variable. When the user enters 'Alice', `name` becomes 'Alice', so the output is 'Hello Alice'.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.