Exercise: Python

Questions for: Console Io

How can you read a character from the console?
A:
input_char()
B:
char(input())
C:
input()[0]
D:
read_character()
Answer: C
To read a character from the console in Python, you can use input()[0] to get the first character of the input string.
What will happen if you use the int() function to convert a non-numeric string?
A:
Error: Cannot convert non-numeric string to integer
B:
The string will be converted to 0
C:
The program will terminate
D:
The string will be printed as is
Answer: A
Using int() on a non-numeric string will result in a ValueError.
How can you check if a string is numeric?
A:
isnumeric()
B:
numeric_check()
C:
str.isnumeric()
D:
isdigit()
Answer: C
You can use str.isnumeric() to check if a string is numeric in Python.
What is the purpose of the sep parameter in the print() function?
A:
Sets the output separator between arguments
B:
Sets the end character at the end of the printed string
C:
Controls the formatting of the printed string
D:
Defines the width of the printed string
Answer: A
The sep parameter in print() sets the output separator between the arguments.
How can you read a list of integers from the console?
A:
list(input().split())
B:
int_list = input().to_list()
C:
list(map(int, input().split()))
D:
read_integer_list()
Answer: C
To read a list of integers from the console, you can use list(map(int, input().split())).
Ad Slot (Above Pagination)
Quiz