• Register
1 vote
184 views

Problem:

Hello all,

I am a new, college student who is learning python programming. I am thinking to write a program that will input a text file and read all the vowels from it and determines when it comes to the end of the file. So, is it possible to create a while loop that determines when the end of a file has been reached?

Thanks in advance.

12 7 7
15,250 points

1 Answer

0 votes

Solution:

The answer is: YES! You can write a code that read vowels from the input text and determines the end of the line.
 

vowels = {'A','E','I','O','U','a','e','i','o','u'}

with open('my_file.txt') as f:
    vow = sum(ch in vowels for line in f for ch in line.strip())
while True:
    line = f.readline().strip()
    if line == '':
        break

Here, we defined our vowels and checked it into our input, and then checked through a While-loop if it reaches the end of the line or not!

Hence, (‘ ‘) define an empty string or (EOL) and of the line.

Thanks.

13 9 6
94,240 points

Related questions

1 vote
1 answer 303 views
303 views
Problem: Hello Pal, I have a query regarding the python programming language. The question is, which method will return an empty string when it has attempted to read beyond the end of a file? Do you have any idea about this? Thanks
asked Mar 16 Gavin 15.3k points
1 vote
1 answer 42 views
42 views
Problem: I wrote a program that asks the user to enter the amount of a purchase and then it sums up the total bill with 15% vat and 0.07% service tax. I wrote the program in python: vat = 0.15 sales_tax = 0.075 product_price = float(input("Please enter the ... not defined I can not solve this thing. I am new in python programming language so please help me to solve this error. Thanks in advance.
asked May 6 samhaz 5k points
0 votes
1 answer 6 views
6 views
Problem: Hi there! I want my while loop to stop after it reaches a certain point and jump out of the loop. Is there any mechanism that I can use? Please help!
asked Oct 12 Sheeza 2.3k points
1 vote
1 answer 14 views
14 views
Problem: I'm working on a simple python program that creates a circle "button" and then having the user click within the circle. If they don't click on the circle, a message pop-up stating that they have clicked outside of the circle area and should give a try again. However, in the ... x-100)**2) +((y-250)**2)) if length == rad or length < rad: break print("Please click within the spin button")
asked Jun 1 adamSw 11.3k points
1 vote
1 answer 38 views
38 views
Problem: Hello people I am doing python programming for a few days. I am still learning. Could anybody please help me by showing how can I import a text file and read five lines from it by my python program? If possible make it as easy words as possible for me. Thanks.
asked Mar 11 Gavin 15.3k points