1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Lyrx [107]
3 years ago
14

"Players The files SomePlayers.txt initially contains the names of 30 football play- ers. Write a program that deletes those pla

yers from the file whose names do not begin with a vowel."

Computers and Technology
1 answer:
kumpel [21]3 years ago
8 0

Answer:

I am writing a Python program that deletes players from the file whose names whose names do not begin with a vowel which means their names begin with a consonant instead. Since the SomePlayers.txt is not provided so i am creating this file. You can simply use this program on your own file.

fileobj= open('SomePlayers.txt', 'r')  

player_names=[name.rstrip() for name in fileobj]  

fileobj.close()  

vowels = ('a', 'e', 'i', 'o', 'u','A','E','I','O','U')

player_names=[name for name in player_names  

                     if name[0] in vowels]

fileobj.close()

print(player_names)

Explanation:

I will explain the program line by line.

First SomePlayers.txt is opened in r mode which is read mode using open() method. fileobj is the name of the file object created to access or manipulate the SomePlayers.txt file. Next a for loop is used to move through each string in the text file and rstrip() method is used to remove white spaces from the text file and stores the names in player_names. Next the file is closed using close() method. Next vowels holds the list of characters which are vowels including both the upper and lower case vowels.

player_names=[name for name in player_names  

                     if name[0] in vowels]

This is the main line of the code. The for loop traverses through every name string in the text file SomePlayers.txt which was first stored in player_names when rstrip() method was used. Now the IF condition checks the first character of each name string. [0] is the index position of the first character of each players name. So the if condition checks if the first character of the name is a vowel or not. in keyword is used here to check if the vowel is included in the first character of every name in the file. This will separate all the names that begins with a vowel and stores in the list player_names. At the end the print statement print(player_names) displays all the names included in the player_names which begin with a vowel hence removing all those names do not begin with a vowel.

You might be interested in
What does it mean if my ninja blender power light is blinking?
Dafna11 [192]
It will only blink if the Ninja Blender's top isn't on all the way.
7 0
3 years ago
Read 2 more answers
The main advantage of a solid state drive is:
Sonbull [250]

the answer is they can store more information

4 0
3 years ago
In which of the following situations may the taxpayer take an education expense on Schedule C? a. Henry, a self-employed adminis
daser333 [38]

Answer:

Henry, an administrative assistant, is taking an advanced Word computer program class through an adult school program.  

Explanation:

4 0
3 years ago
Which of the following can you use to attach external hardware devices to a computer?
Genrish500 [490]

The answer is c that what a lot of people use☻

5 0
3 years ago
Read 2 more answers
Using this statement to answer the following question “FIFA World Cup 2010: (1+9) From Today!” (Ignore Quotation)
Yuliya22 [10]
Free space going around the town states
5 0
3 years ago
Other questions:
  • What should a career plan include?
    7·1 answer
  • What is one visual indication that a usb port can be used to charge a mobile device?
    13·1 answer
  • Which protocol is used by the client for microsoft networks and file and printer sharing for microsoft networks to communicate w
    10·1 answer
  • Select a classification for File2 so that: Alice can read and write to File2 Bob and Charlie can write to File2, but can't read
    6·1 answer
  • Fedora operating system
    9·1 answer
  • Quiz
    6·2 answers
  • Given an int variable k, an int array incompletes that has been declared and initialized, an int variable nIncompletes that cont
    6·1 answer
  • Do you have any sprites for Friday Night Funkin?
    14·1 answer
  • How media platform drives globalization.<br> Advantages and disadvantages of using media platforms?
    7·1 answer
  • What feature should you enable to prevent the sidhistory attribute from being used to falsely gain administrative privileges in
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!