Exercise: Python

Questions for: Console Io

Which of the following is used to format the output?
A:
format()
B:
print_format()
C:
string.format()
D:
f-string
Answer: D
In Python, f-string is used for formatting output by embedding expressions inside string literals.
What is the purpose of the sys.stdin stream?
A:
Reading input from the console
B:
Writing output to the console
C:
Standard error input
D:
Redirecting output to a file
Answer: A
sys.stdin is the standard input stream in Python, used for reading input from the console.
How can you clear the screen in a Python console application?
A:
console.clear()
B:
os.clear()
C:
clear()
D:
os.system("clear")
Answer: D
You can use os.system("clear") to clear the screen in a Python console application.
How can you prompt the user with a message while taking input?
A:
prompt(input_msg)
B:
input_msg(prompt)
C:
input(prompt=input_msg)
D:
console.prompt(input_msg)
Answer: C
You can use the input() function with the optional parameter prompt to display a message to the user before taking input.
What will happen if you try to use input() without assigning it to a variable?
A:
Error: input() cannot be used without assignment
B:
The input will be ignored
C:
The program will terminate
D:
The input will be printed to the console
Answer: D
If you use input() without assigning it to a variable, the entered input will be displayed on the console.
Ad Slot (Above Pagination)
Quiz