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?
password = input("Enter password: ")
password = getpass.getpass("Enter password: ")
password = read_password()
password = input_password()
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?
print("First:", string[0], "Last:", string[-1])
print("First:", string.first(), "Last:", string.last())
print(f"First: {string[0]}, Last: {string[-1]}")
print("First:", first_char(string), "Last:", last_char(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?
capitalize_words(input())
input().title()
capitalize_first_letter(input())
input().capitalize_words()
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?
print_progress_bar()
progressbar.print()
print("\u2588" * 10)
console.print_progress()
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?
word_count(input())
count_words(input())
word_occurrences = Counter(input().split())
input().count_words()
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.