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
You have just provided the identification number that associates your new software purchase with the mobile device on which you
Lunna [17]
<span>software deployment, software decryption, app installation, product activation

Are those the answers to choose from?

</span>
5 0
2 years ago
Which of these is system software? Check all
Darya [45]

Answer:

Windows OS is software....

6 0
3 years ago
On an XBOX 360, what does it mean if you get 4 red rings on your console?
Hitman42 [59]

Answer:

C. This happened to me.

Explanation:

4 0
3 years ago
. What projects would Excel best be used for?
adoni [48]

Answer:

Projects that require spreadsheet organization and/or calculations between data

Explanation:

That is why Excel is a spreadsheet program

7 0
2 years ago
write a program that generates 100 random integrs between 0 and 9 and displays the count for each number. (Hint: Use (int) (math
Nataly_w [17]

Answer: The java program to generate 100 random numbers and count their occurrence is shown below.

import java.util.Random;

import java.util.*;

public class MyClass {

   public static void main(String args[]) {

     int[]count = new int[10];

// temporarily stores the randomly generated number

     int num;

     for(int i=0; i<10; i++)

     {

// initialize count of all digits from 0 to 9 to zero

           count[i] = 0;

     }

     for(int i=0; i<100; i++)

     {

// generates 100 random numbers or integers from 0 through 9

           num = (int) (Math.random() * 10);

           for(int j=0; j<10; j++)

           {

// compare each randomly generated number with digits from 0 to 9 and increment their count accordingly

               if(num == j)

                   count[j] = count[j]+1;

           }

     }

     System.out.println("The count of randomly generated numbers is shown below.");

     for(int i=0; i<10; i++)

     {

           System.out.println("Count of "+i+" is "+ count[i]);

     }

   }

}

OUTPUT

The count of randomly generated numbers is shown below.

Count of 0 is 10

Count of 1 is 8

Count of 2 is 13

Count of 3 is 10

Count of 4 is 9

Count of 5 is 13

Count of 6 is 7

Count of 7 is 11

Count of 8 is 9

Count of 9 is 10

Explanation: This program declares an integer array of size 10 and initializes it to 0.

Random numbers are generated as shown. The number is randomly generated in an outer for loop with executes 100 times for 100 numbers.

(int) (Math.random() * 10)

The package java.util.Math is imported to serve the purpose.

The above code generates random numbers which can be floating numbers. The integer part is extracted using (int).

This yields the digits from 0 through 9.

For every occurrence of digits from 0 to 9, the count of the index of the respective digit is incremented.

To serve this purpose, inner for loop is implemented. The variable used in this loop is compared with the random number and index of count incremented accordingly. The inner for loop runs 10 times at the maximum, in order to match random number with 0 through 9.

Lastly, the occurrence of every digit from 0 to 9 is displayed.

8 0
3 years ago
Other questions:
  • Prompt the user for an automobile service. Each service type is composed of two strings. Output the user's input. (1 pt) Ex: Ent
    9·1 answer
  • To become a news anchor, you should get a Bachelor's degree in:
    11·2 answers
  • What is an example of constructive criticism for an employee who is shy during meetings?
    15·2 answers
  • 6.
    14·2 answers
  • _______ is a form of crime that targets a computer system to acquire information stored on that computer system, to control the
    15·1 answer
  • What single awk command can be used to display all the login names and their associated numerical user IDs
    14·1 answer
  • Pick one of the following scenarios and
    6·1 answer
  • All banks follow the same guideline for determining if an applicant qualifies for a loan.
    13·1 answer
  • I need subscribers plz ​
    15·2 answers
  • Without using parentheses, enter a formula in cell F4 that
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!