Python Programming - Console Input/Output
Exercise : Console Input/Output - General Questions
- Console Input/Output - General Questions
61.
How can you prompt the user to enter a sentence and count the number of vowels?
Answer: Option
Explanation:
To prompt the user to enter a sentence and count the number of vowels, use
sentence = input("Enter a sentence: "); print(sum(1 for char in sentence if char.lower() in 'aeiou'))
.
62.
How can you read a list of numbers from the console and find their average?
Answer: Option
Explanation:
To read a list of numbers from the console and find their average, use
numbers = input("Enter numbers separated by spaces: "); print(sum(map(int, numbers.split())) / len(numbers))
.
63.
How can you print the factorial of a number entered by the user?
Answer: Option
Explanation:
To print the factorial of a number entered by the user, use
print(factorial(int(input("Enter a number: "))))
.
64.
How can you read two integers from the console and swap their values?
Answer: Option
Explanation:
To read two integers from the console and swap their values, use
a, b = input("Enter two numbers: ").split(); a, b = b, a; print(a, b)
.
65.
How can you print the ASCII value of a character entered by the user?
Answer: Option
Explanation:
To print the ASCII value of a character entered by the user, use
ascii_value = ord(input("Enter a character: ")); print(ascii_value)
.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers