Python Programming - Console Input/Output
Exercise : Console Input/Output - General Questions
- Console Input/Output - General Questions
71.
How can you prompt the user to enter a series of numbers until they enter a negative number, and then print the sum of the positive numbers?
Answer: Option
Explanation:
To prompt the user to enter a series of numbers until they enter a negative number, and then print the sum of the positive numbers, use a
while
loop with a break condition.
72.
How can you read a string from the console, count the number of vowels and consonants, and print the result?
Answer: Option
Explanation:
To read a string from the console, count the number of vowels and consonants, and print the result, use
string_input = input("Enter a string: "); print("Vowels:", count_vowels(string_input), "Consonants:", count_consonants(string_input))
.
73.
How can you prompt the user to enter a list of words, sort them alphabetically, and print the result?
Answer: Option
Explanation:
To prompt the user to enter a list of words, sort them alphabetically, and print the result, use
words = input("Enter words separated by spaces: ").split(); print("Sorted words:", sort_words(words))
.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers