Console Input/Output Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q21
How to format a number to 2 decimal places in output?
  • A Using round() function
  • B Using f-string with .2f
  • C Using format() with {:.2f}
  • D All of the above
Answer: Option D
Explanation: f-strings or format() method with formatting specifications can control decimal places in output.
Q22
What is the difference between print and return?
  • A Both are same
  • B print outputs to console, return gives function result
  • C return outputs to console, print gives function result
  • D print is for numbers, return is for strings
Answer: Option B
Explanation: print displays output to console, while return sends a value back from a function to the caller.
Q23
How to read password input without displaying it?
  • A Using input(hidden=True)
  • B Using getpass.getpass()
  • C Using password_input()
  • D Using secure_input()
Answer: Option B
Explanation: The getpass module provides getpass() function that reads input without echoing it to the screen.
Q24
What does the file parameter in print() do?
  • A Specifies filename to read
  • B Redirects output to file
  • C Formats file content
  • D Encodes the output
Answer: Option B
Explanation: The file parameter redirects output to a file-like object instead of standard output (console).
Q25
How to display a backslash character in string?
  • A \
  • B \\
  • C /
  • D //
Answer: Option B
Explanation: Backslash is escape character, so to display it, use double backslash \\.
Questions and Answers for Competitive Exams Various Entrance Test