Python Programming - Console Input/Output
Exercise : Console Input/Output - General Questions
- Console Input/Output - General Questions
51.
How can you print a countdown from 5 to 1?
Answer: Option
Explanation:
To print a countdown from 5 to 1, use a loop with
reversed(range(1, 6)).
52.
How can you read a string from the console and check if it contains the substring "python"?
Answer: Option
Explanation:
To read a string from the console and check if it contains the substring "python", use the
in keyword.
53.
How can you print the sum of even numbers from 1 to 10?
Answer: Option
Explanation:
To print the sum of even numbers from 1 to 10, use
sum(range(2, 11, 2)).
54.
How can you prompt the user to enter a floating-point number and round it to the nearest integer?
Answer: Option
Explanation:
To prompt the user to enter a floating-point number and round it to the nearest integer, use
round(float(input("Enter a number: "))).
55.
How can you read a line of text from the console, remove leading and trailing whitespaces, and convert it to uppercase?
Answer: Option
Explanation:
To read a line of text from the console, remove leading and trailing whitespaces, and convert it to uppercase, use
input().strip().upper().
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers