Console Input/Output Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q11
What is the purpose of the prompt message in input()?
  • A To store the input value
  • B To guide the user about expected input
  • C To validate the input
  • D To format the output
Answer: Option B
Explanation: The prompt message in input() is displayed to the user to indicate what kind of input is expected.
Q12
Which escape sequence adds a tab space in print()?
  • A \n
  • B \t
  • C \s
  • D \tab
Answer: Option B
Explanation: Escape sequences start with backslash. \t adds a tab space, \n adds newline, \\ adds backslash itself.
Q13
How to read multiple inputs in a single line?
  • A Using multiple input() calls
  • B Using input().split()
  • C Using readline()
  • D Using getinput()
Answer: Option B
Explanation: split() method can be used with input() to read multiple values separated by spaces in one line.
Q14
What does the flush parameter in print() do?
  • A Clears the screen
  • B Forces immediate output
  • C Removes spaces
  • D Formats numbers
Answer: Option B
Explanation: The flush parameter forces the output to be written immediately instead of buffering. Default is False.
Q15
Which method is used to convert input to floating-point number?
  • A int()
  • B float()
  • C decimal()
  • D number()
Answer: Option B
Explanation: float() function converts strings to floating-point numbers, useful for decimal input.
Q16
How to display special characters like quotes in strings?
  • A Using escape sequences
  • B Using different quote types
  • C Using triple quotes
  • D All of the above
Answer: Option D
Explanation: Escape sequences with backslash or using different quote types allows displaying special characters.
Q17
What is the output of: print(10, 20, 30, sep="::")?
  • A 10 20 30
  • B 10::20::30
  • C 10,20,30
  • D 102030
Answer: Option B
Explanation: The sep parameter replaces the default space separator with the specified string between values.
Q18
How to handle EOFError in input()?
  • A Using if-else
  • B Using try-except
  • C Using while loop
  • D Using break statement
Answer: Option B
Explanation: EOFError occurs when input() reaches end-of-file. It can be handled using try-except block.
Q19
Which function was used for console input in Python 2?
  • A scanf()
  • B raw_input()
  • C get_input()
  • D console_input()
Answer: Option B
Explanation: In Python 2, raw_input() was used for string input and input() evaluated the input as Python expression.
Q20
What is the output of: print("A", "B", "C", end="!")?
  • A A B C
  • B A B C!
  • C A!B!C!
  • D ABC!
Answer: Option B
Explanation: The end parameter replaces the default newline with the specified string at the end of output.
Questions and Answers for Competitive Exams Various Entrance Test