Mastering Python’s sep= and end= Parameters for PCEP-30-02
PCEP Certification Practice Test - Questions, Answers and Explanations
This comprehensive set of questions and explanations covers the essential topic of performing Input/Output console operations with a focus on the sep= and end= keyword parameters. These interactions will enhance your understanding and preparation for the PCEP-30-02 examination.
Question 1: What will be the output of the following code?
print("Hello", "World", sep=", ")
- Hello World
- Hello, World
- Hello,World
- Hello World,
Answer: b) Hello, World
Explanation: The sep="," parameter in the print() function specifies that a comma followed by a space should be used to separate the values.
Question 2: What will be the output of the following code?
print("Python", "Programming", end="!")
- Python Programming
- Python! Programming!
- Python Programming!
- Python! Programming
Answer: c) Python Programming!
Explanation: The end="!" parameter in the print() function specifies that the output should end with an exclamation mark instead of the default newline.
Question 3: What will be the output of the following code?
print("PCEP", "Exam", sep="*", end="!!")
- PCEP Exam
- PCEP*Exam!!
- PCEP*Exam
- PCEP Exam!!
Answer: b) PCEP*Exam!!
Explanation: The sep="*" parameter separates the two strings with an asterisk, and end="!!" appends two exclamation marks at the end.
Question 4: Which of the following statements will output apple-banana-cherry on a single line? (Select all that apply)
- print("apple", "banana", "cherry", sep="-")
- print("apple-banana-cherry")
- print("apple", "banana", "cherry", sep="")
- print("apple", "banana", "cherry", sep="-", end="")
Answer: a) print("apple", "banana", "cherry", sep="-"), b) print("apple-banana-cherry"), d) print("apple", "banana", "cherry", sep="-", end="")
Explanation: Options a), b), and d) will all correctly output apple-banana-cherry with the specified separator. Option c) does not include the separator and will produce applebananacherry.
Question 5: Which of the following statements will print Learn!Python!Programming? (Select all that apply)
- print("Learn", "Python", "Programming", sep="!")
- print("Learn", "Python", sep="!", end="!Programming")
- print("Learn!Python!Programming")
- print("Learn", "Python", "Programming", sep="!", end="!")
Answer: a) print("Learn", "Python", "Programming", sep="!"), c) print("Learn!Python!Programming")
Explanation: Both options a) and c) will produce the desired output. Option b) sep="!": This sets the separator between "Learn" and "Python" to !, so it correctly prints Learn!Python. end="!Programming": This adds !Programming at the end of the output after "Python" and prevents a newline from being added, resulting in Learn!Python!Programming. Technically, this does produce the correct string, but in the context of the specific question, the focus is on using the sep parameter to insert ! between all words. The sentence structure in the context of the question expects all three words to be separated by ! using sep, not by combining sep and end. d) The statement print("Learn", "Python", "Programming", sep="!", end="!") will print Learn!Python!Programming! with an extra ! at the end, not just Learn!Python!Programming. This statement is not correct for producing the exact output you want.
Question 6: Arrange the following parameters to achieve the output Coding@Python#2024: sep="@", end="#2024".
- end="#2024"
- sep="@"
Answer:
- sep="@"
- end="#2024"
Explanation: sep="@" should be used to join the words with an "@" symbol, and end="#2024" should be used to append #2024 at the end.
Question 7: The ______ parameter in the print() function is used to specify the string to be printed between multiple values.
▼Answer: sep=
Explanation: The sep= parameter specifies the string that should be used as a separator between the values being printed.
Question 8: The ______ parameter in the print() function is used to specify the string to be printed at the end of the output.
▼Answer: end=
Explanation: The end= parameter specifies what should be printed at the end of the output, replacing the default newline.
Question 9: Which of the following code snippets in the order that would result in the output Python is great!:
- print("Python", "is", "great", sep=" ")
- print("Python", "is", "great", sep=" ", end="!")
- print("Python", "is", "great", sep="")
Answer:
- print("Python", "is", "great", sep=" ", end="!")
Explanation: The second option correctly places a space between each word and adds an exclamation mark at the end, resulting in Python is great!.
Question 10: Fill in the missing code to output Python-Rocks! using the sep= and end= parameters.
print("Python", "Rocks", sep="____", end="____")▼
Answer: "-", "!"
Explanation: The correct code is print("Python", "Rocks", sep="-", end="!"), which outputs Python-Rocks!.
Question 11: Fill in the missing code to output Data;Science;Machine;Learning.
print("Data", "Science", "Machine", "Learning", sep="____")▼
Answer: ";"
Explanation: The correct code is print("Data", "Science", "Machine", "Learning", sep=";"), which outputs Data;Science;Machine;Learning.
Question 12: Insert the correct parameter to output Learning~Python from the following code.
print("Learning", "Python", sep="____")▼
Answer: ~
Explanation: The correct code is print("Learning", "Python", sep="~"), which results in Learning~Python.
Question 13: Insert the correct parameter to end the output with !! instead of a newline.
print("Goodbye", "World", end="____")▼
Answer: " !!"
Explanation: The correct code is print("Goodbye", "World", end="!!"), which ends the output with !! instead of a newline.
Question 14: What will be the output of the following code?
print("Line 1", end="..."); print("Line 2", end="!!!")
- Line 1...Line 2!!!
- Line 1 Line 2
- Line 1... Line 2!!!
- Line 1.Line 2!
Answer: a) Line 1...Line 2!!!
Explanation: The end="..." in the first print() appends ... after Line 1, and the second print() appends !!! after Line 2.
Question 15: What will be the output of the following code?
print("Start", end="-->"); print("End", end=".")
- Start-->End.
- Start End.
- Start--> End.
- Start End-->.
Answer: a) Start-->End.
Explanation: The end="-->" parameter in the first print() adds --> after Start, and the second print() adds a period after End.
Question 16: Which of the following outputs can be generated by using the sep=":" parameter? (Select all that apply)
- 1:2:3
- 1:2:3:4
- 1 2 3
- 123
Answer: a) 1:2:3, b) 1:2:3:4
Explanation: The sep=":" parameter separates values with a colon. Options c) and d) do not match this output.
Question 17: Which of the following statements will output Hello-Python-World!? (Select all that apply)
- print("Hello", "Python", "World", sep="-")
- print("Hello", "Python", sep="-", end="-World!")
- print("Hello-Python-World!")
- print("Hello", "Python", "World", sep="-", end="!")
Answer: c) print("Hello-Python-World!"), d) print("Hello", "Python", "World", sep="-", end="!")
Explanation: Options c) and d) correctly format the output with hyphens and an exclamation mark.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python/certificate/perform-input-output-console-operations-sep-and-end-keyword-parameters.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics