Python Programming - Console Input/Output
Exercise : Console Input/Output - General Questions
- Console Input/Output - General Questions
31.
How can you read a string from the console and reverse it?
Answer: Option
Explanation:
To read a string from the console and reverse it in Python, use slicing with
[::-1]
.
32.
How can you print the current date and time in a specific format?
Answer: Option
Explanation:
To print the current date and time in a specific format, use
strftime("%Y-%m-%d %H:%M:%S")
with the datetime
object.
33.
How can you read multiple lines of text from the console until a specific keyword is entered?
Answer: Option
Explanation:
To read multiple lines of text until a specific keyword is entered, use a
while
loop with a conditional break.
34.
How can you print a table of values with aligned columns?
Answer: Option
Explanation:
To print a table of values with aligned columns, use a loop and f-string formatting with alignment.
35.
How can you read a list of strings from the console until an empty line is entered?
Answer: Option
Explanation:
To read a list of strings until an empty line is entered, use a
while
loop with a conditional break.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers