Python Programming - Console Input/Output
Exercise : Console Input/Output - General Questions
- Console Input/Output - General Questions
66.
How can you read a string from the console, replace all spaces with underscores, and print the result?
Answer: Option
Explanation:
To read a string from the console, replace all spaces with underscores, and print the result, use
string_input = input("Enter a string: "); print(string_input.replace(" ", "_"))
.
67.
How can you check if a given year is a leap year or not?
Answer: Option
Explanation:
To check if a given year is a leap year or not, use
is_leap(int(input("Enter a year: ")))
.
68.
How can you read a sentence from the console, find the length of each word, and print the result?
Answer: Option
Explanation:
To read a sentence from the console, find the length of each word, and print the result, use
sentence = input("Enter a sentence: "); print([len(word) for word in sentence.split()])
.
69.
How can you prompt the user to enter three numbers and find the maximum among them?
Answer: Option
Explanation:
To prompt the user to enter three numbers and find the maximum among them, use
print("Maximum:", max(input("Enter three numbers: ").split()))
.
70.
How can you read a list of integers from the console, remove duplicates, and print the result?
Answer: Option
Explanation:
To read a list of integers from the console, remove duplicates, and print the result, use
numbers = input("Enter integers separated by spaces: "); print(list(set(map(int, numbers.split()))))
.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers