Python Programming - Console Input/Output
Exercise : Console Input/Output - General Questions
- Console Input/Output - General Questions
41.
How can you read a password from the console without echoing characters?
Answer: Option
Explanation:
To read a password from the console without echoing characters, use
getpass.getpass()
.
42.
How can you print the first and last characters of a string?
Answer: Option
Explanation:
To print the first and last characters of a string, use indexing with
string[0]
and string[-1]
.
43.
How can you read a line of text from the console and capitalize the first letter of each word?
Answer: Option
Explanation:
To read a line of text from the console and capitalize the first letter of each word, use
title()
.
44.
How can you print a progress bar in the console using Python?
Answer: Option
Explanation:
To print a simple progress bar in the console, you can use the Unicode block character (\u2588) repeated a certain number of times.
45.
How can you read a line of text from the console and count the occurrences of each word?
Answer: Option
Explanation:
To read a line of text from the console and count the occurrences of each word, use
Counter(input().split())
from the collections
module.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers