Python Programming - Console Input/Output
Exercise : Console Input/Output - General Questions
- Console Input/Output - General Questions
46.
How can you prompt the user for a yes/no response?
Answer: Option
Explanation:
To prompt the user for a yes/no response, use
input("Yes or no? (y/n): ")
.
47.
How can you align text to the center in a Python console output?
Answer: Option
Explanation:
Using the f-string format
{text:^10}
aligns the text to the center within a 10-character wide space.
48.
How can you read an integer from the console and check if it is within a specific range?
Answer: Option
Explanation:
To read an integer from the console and check if it is within a specific range, use conditional statements with the
int()
function.
49.
How can you print the square of numbers from 1 to 5?
Answer: Option
Explanation:
To print the square of numbers from 1 to 5, use a loop with
range(1, 6)
and calculate the square with num * num
.
50.
How can you read a list of comma-separated values from the console and convert them to integers?
Answer: Option
Explanation:
To read a list of comma-separated values from the console and convert them to integers, use
list(map(int, input().split(',')))
.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers