Computer Science
Write a function, vowelCount() in Python that counts and displays the number of vowels in the text file named Poem.txt.
Python File Handling
2 Likes
Answer
The Poem.txt file includes following data :
The sun sets in the west.
To be successful, one must work hard.
def vowelCount():
fobj = open("Poem.txt", "r")
data = str(fobj.read())
cnt = 0
for ch in data:
if ch in "aeiouAEIOU":
cnt = cnt + 1
print(cnt)
fobj.close()
vowelCount()
Output
16
Answered By
3 Likes
Related Questions
Consider the table CLUB given below and write the output of the SQL queries that follow.
CID CNAME AGE GENDER SPORTS PAY DOAPP 5246 AMRITA 35 FEMALE CHESS 900 2006-03-27 4687 SHYAM 37 MALE CRICKET 1300 2004-04-15 1245 MEENA 23 FEMALE VOLLEYBALL 1000 2007-06-18 1622 AMRIT 28 MALE KARATE 1000 2007-09-05 1256 AMINA 36 FEMALE CHESS 1100 2003-08-15 1720 MANJU 33 FEMALE KARATE 1250 2004-04-10 2321 VIRAT 35 MALE CRICKET 1050 2005-04-30 (i) SELECT COUNT(DISTINCT SPORTS) FROM CLUB;
(ii) SELECT CNAME, SPORTS FROM CLUB WHERE DOAPP<"2006-04-30" AND CNAME LIKE "%NA";
(iii) SELECT CNAME, AGE, PAY FROM CLUB WHERE GENDER = "MALE" AND PAY BETWEEN 1000 AND 1200;
Write a function in Python to read a text file, Alpha.txt and displays those lines which begin with the word ‘You’.
Consider the table Personal given below:
Table: Personal
P_ID Name Desig Salary Allowance P01 Rohit Manager 89000 4800 P02 Kashish Clerk NULL 1600 P03 Mahesh Superviser 48000 NULL P04 Salil Clerk 31000 1900 P05 Ravina Superviser NULL 2100 Based on the given table, write SQL queries for the following:
(i) Increase the salary by 5% of personals whose allowance is known.
(ii) Display Name and Total Salary (sum of Salary and Allowance) of all personals. The column heading 'Total Salary' should also be displayed.
(iii) Delete the record of personals who have salary greater than 25000.
A list, NList contains following record as list elements:
[City, Country, distance from Delhi]
Each of these records are nested together to form a nested list. Write the following user defined functions in Python to perform the specified operations on the stack named travel.
(i) Push_element(NList): It takes the nested list as an argument and pushes a list object containing name of the city and country, which are not in India and distance is less than 3500 km from Delhi.
(ii) Pop_element(): It pops the objects from the stack and displays them. Also, the function should display “Stack Empty” when there are no elements in the stack.
For example: If the nested list contains the following data:
NList=[["New York", "U.S.A.", 11734], ["Naypyidaw", "Myanmar", 3219], ["Dubai", "UAE", 2194], ["London", "England", 6693], ["Gangtok", "India", 1580], ["Columbo", "Sri Lanka", 3405]]
The stack should contain:
['Naypyidaw', 'Myanmar'], ['Dubai', 'UAE'], ['Columbo', 'Sri Lanka']
The output should be:
['Columbo', 'Sri Lanka'] ['Dubai', 'UAE'] ['Naypyidaw', 'Myanmar'] Stack Empty