w3resource

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=", ")
  1. Hello World
  2. Hello, World
  3. Hello,World
  4. 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="!")
  1. Python Programming
  2. Python! Programming!
  3. Python Programming!
  4. 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="!!")
  1. PCEP Exam
  2. PCEP*Exam!!
  3. PCEP*Exam
  4. 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)

  1. print("apple", "banana", "cherry", sep="-")
  2. print("apple-banana-cherry")
  3. print("apple", "banana", "cherry", sep="")
  4. 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)

  1. print("Learn", "Python", "Programming", sep="!")
  2. print("Learn", "Python", sep="!", end="!Programming")
  3. print("Learn!Python!Programming")
  4. 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!:

  1. print("Python", "is", "great", sep=" ")
  2. print("Python", "is", "great", sep=" ", end="!")
  3. print("Python", "is", "great", sep="")

Answer:

  1. 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="!!!")
  1. Line 1...Line 2!!!
  2. Line 1 Line 2
  3. Line 1... Line 2!!!
  4. 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=".")
  1. Start-->End.
  2. Start End.
  3. Start--> End.
  4. 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. 1:2:3
  2. 1:2:3:4
  3. 1 2 3
  4. 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)

  1. print("Hello", "Python", "World", sep="-")
  2. print("Hello", "Python", sep="-", end="-World!")
  3. print("Hello-Python-World!")
  4. 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.



Become a Patron!

Follow us on Facebook and Twitter for latest update.