Exercise: Console Io

Questions for: Console Io

How can you print the sum of even numbers from 1 to 10?
A:
print(sum(range(2, 11, 2)))
B:
even_sum(1, 10)
C:
print(even_numbers_sum(1, 10))
D:
sum_even(range(1, 11))
Answer: A
To print the sum of even numbers from 1 to 10, use sum(range(2, 11, 2)).
How can you read a string from the console and check if it contains the substring "python"?
A:
contains_python(input())
B:
check_substring(input(), "python")
C:
input().has_substring("python")
D:
print("Python" in input())
Answer: D
To read a string from the console and check if it contains the substring "python", use the in keyword.
How can you print a countdown from 5 to 1?
A:
countdown(5, 1)
B:
for num in reversed(range(1, 6)): print(num)
C:
print_countdown(5)
D:
print(5, 4, 3, 2, 1)
Answer: B
To print a countdown from 5 to 1, use a loop with reversed(range(1, 6)).
How can you read a list of comma-separated values from the console and convert them to integers?
A:
input().split(',').to_int()
B:
list(map(int, input().split(',')))
C:
read_comma_separated_integers()
D:
convert_to_int(input().split(','))
Answer: B
To read a list of comma-separated values from the console and convert them to integers, use list(map(int, input().split(','))).
How can you print the square of numbers from 1 to 5?
A:
for num in range(1, 6): print(num * num)
B:
print_squares([1, 2, 3, 4, 5])
C:
squares_print(1, 5)
D:
print(range(1, 6) ** 2)
Answer: A
To print the square of numbers from 1 to 5, use a loop with range(1, 6) and calculate the square with num * num.
Ad Slot (Above Pagination)
Quiz