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 TYPE of flash drive is called when it saves your files safely? I'm going to use my friend computer that's why.
Lilit [14]

Answer:

A good Universal serial bus i use is a San Disk

Explanation:

others are a WD easystore, A samsung MUF-BA.... etc

8 0
3 years ago
Consider the cement used for the foundation; the bricks and timber used for the walls; and the shingles used for the roof. All o
gavmur [86]
<span>Consider the cement used for the foundation; the bricks and timber used for the walls; and the shingles used for the roof. All of these are __________ in making the house.

A. Elements</span>
6 0
3 years ago
Select the correct navigational path to set the name for a cell range.
S_A_V [24]

Answer: formula tab, defined names, name manager

Explanation:

ed 2020

6 0
3 years ago
Read 2 more answers
Sharon is thinking about opening a bakery. She knows she wants to set her own hours, reduce her stress and make a profit. But sh
kondaur [170]
C would not be a beginner move.

hope it helps
6 0
3 years ago
What a suitable variable name to store the number of years old a person is
navik [9.2K]

age is a suitable variable name. It's descriptive and concise. Make sure it's lowercase.

8 0
3 years ago
Other questions:
  • In the database below, the arrow is pointing to a _____.<br> file<br> record<br> field<br> key field
    12·1 answer
  • Survey Q, Non-scoring: What role are you playing in your team?
    5·2 answers
  • Hi Im really a girl and i want to know how to change my username without having to make a new account?
    9·2 answers
  • HELP ASAP U GET BRAINLIEST
    15·2 answers
  • How does this app work?
    11·2 answers
  • A growling noise is heard only when the driver exerts force on the clutch pedal. No noise is heard when the clutch pedal is up.
    14·1 answer
  • Write a program that declares a constant named QUARTS_IN_GALLON which holds the number of quarts in a gallon (4). Also declare a
    8·1 answer
  • A<br>A<br>printount<br>of your report or a till slip is an<br>example of what​
    15·1 answer
  • Based on the following quote from Leonardo Da Vinci, what would be his definition of a fine artist? “Principles for the Developm
    11·2 answers
  • A. A set of electronic program that makes of computer perform tasks
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!