Python Programming - Console Input/Output

Exercise : Console Input/Output - General Questions
  • Console Input/Output - General Questions
26.
How can you align text to the right in a Python console output?
align_right("text")
print("text", align="right")
print(f"{text:>10}")
right_align("text")
Answer: Option
Explanation:
Using the f-string format {text:>10} aligns the text to the right within a 10-character wide space.

27.
How can you read a line of text from the console and split it into words?
read_line().split()
line.split(input())
input().split()
split_line(input())
Answer: Option
Explanation:
To read a line of text from the console and split it into words, you can use input().split().

28.
How can you print a multiline string?
print("Line 1\nLine 2")
multiline_print("Line 1", "Line 2")
print_multiline("Line 1", "Line 2")
print("Line 1")
print("Line 2")
Answer: Option
Explanation:
To print a multiline string in Python, use newline characters (\n) to separate lines within a single print() statement.

29.
How can you prompt the user for input and convert it to an integer in a single line?
input().convert_to_int()
int(prompt("Enter an integer: "))
user_input = input("Enter an integer: "); int(user_input)
int(input("Enter an integer: "))
Answer: Option
Explanation:
To prompt the user for input and convert it to an integer in a single line, use int(input("Enter an integer: ")).

30.
How can you check if a string contains only alphabetic characters?
str.isalpha()
is_alphabetic(str)
check_alpha(str)
str.only_alpha()
Answer: Option
Explanation:
The isalpha() method is used to check if a string contains only alphabetic characters in Python.