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?
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?
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?
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?
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?
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])
.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers