Python Programming - Console Input/Output

Exercise : Console Input/Output - General Questions
  • Console Input/Output - General Questions
56.
How can you print the sum of all odd numbers from 1 to 10?
print(sum(range(1, 11, 2)))
odd_sum(1, 10)
print(odd_numbers_sum(1, 10))
sum_odd(range(1, 11))
Answer: Option
Explanation:
To print the sum of odd numbers from 1 to 10, use print(sum(range(1, 11, 2))).

57.
How can you read a password from the console and check if it meets certain criteria?
password = input("Enter password: "); validate_password(password)
password = input_password(); check_password_criteria(password)
password = getpass.getpass("Enter password: "); is_valid_password(password)
password = input("Enter password: "); validate_password_criteria(password)
Answer: Option
Explanation:
To read a password from the console and check if it meets certain criteria, use input("Enter password: "); validate_password(password).

58.
How can you prompt the user to enter two numbers and print their product?
product = input("Enter first number: ") * input("Enter second number: "); print(product)
product = int(input("Enter first number: ")) * int(input("Enter second number: ")); print(product)
product = multiply_numbers(input("Enter first number: "), input("Enter second number: ")); print(product)
product = input("Enter first number: ").multiply(input("Enter second number: ")); print(product)
Answer: Option
Explanation:
To prompt the user to enter two numbers and print their product, use int(input("Enter first number: ")) * int(input("Enter second number: ")); print(product).

59.
How can you read an integer from the console and print its square?
square(int(input()))
print_square(input("Enter an integer: "))
num = input("Enter an integer: "); print(int(num) ** 2)
calculate_square(int(input("Enter an integer: ")))
Answer: Option
Explanation:
To read an integer from the console and print its square, use num = input("Enter an integer: "); print(int(num) ** 2).

60.
How can you read a line of text from the console, reverse it, and print the result?
print(reverse(input("Enter a line of text: ")))
line = input("Enter a line of text: "); print(line.reverse())
text = input("Enter a line of text: "); print(text[::-1])
reversed_text = reverse_text(input())
Answer: Option
Explanation:
To read a line of text from the console, reverse it, and print the result, use text = input("Enter a line of text: "); print(text[::-1]).