Exercise: Console Io

Questions for: Console Io

How can you read a line of text from the console and capitalize the first letter of each word?
A:
capitalize_words(input())
B:
input().title()
C:
capitalize_first_letter(input())
D:
input().capitalize_words()
Answer: B
To read a line of text from the console and capitalize the first letter of each word, use title().
How can you print the first and last characters of a string?
A:
print("First:", string[0], "Last:", string[-1])
B:
print("First:", string.first(), "Last:", string.last())
C:
print(f"First: {string[0]}, Last: {string[-1]}")
D:
print("First:", first_char(string), "Last:", last_char(string))
Answer: A
To print the first and last characters of a string, use indexing with string[0] and string[-1].
How can you read a password from the console without echoing characters?
A:
password = input("Enter password: ")
B:
password = getpass.getpass("Enter password: ")
C:
password = read_password()
D:
password = input_password()
Answer: B
To read a password from the console without echoing characters, use getpass.getpass().
How can you format a floating-point number with a specific number of decimal places?
A:
format_float(number, 2)
B:
round(number, 2)
C:
format(number, ".2f")
D:
decimal_format(number, 2)
Answer: C
To format a floating-point number with a specific number of decimal places, use format(number, ".2f").
How can you read multiple integers from the console and store them in a list?
A:
int_list = input().to_list()
B:
list(map(int, input().split()))
C:
read_integers_list()
D:
input().parse_int()
Answer: B
To read multiple integers from the console and store them in a list, use list(map(int, input().split())).
Ad Slot (Above Pagination)
Quiz