Question

Fill in the following code: # Open the file data.csv in read mode data_file = XXXXXX...

Fill in the following code:
# Open the file data.csv in read mode
data_file = XXXXXX

# This is a for loop where line is the variable name
# line will automatically be set to each line of the file data.csv
# and will be different at each iteration of the loop
for XXXX in data_file:
# Create a list called columns, that contains the 4 elements of the row
columns = line.rstrip(XX).split(XX)
# assign the 0th column to the variable species
species = XXXXXX
# assign the 1nd column to the variable name
name = XXXXXX
# assign the 2st column to the variable sequence
sequence = XXXXXX
# assign the 3rd column to the variable expression
expression = XXXXXX
# This is an if condition that prints the contents of the variable name
# if the name of the species is either Drosophila yakuba or
# Drosophila ananassae
if XXXXXXXXXXXXXXX:
print(name)

# Close file
XXXXXXXX

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

# Open the file data.csv in read mode
data_file = open("data.csv",'r')

# This is a for loop where line is the variable name
# line will automatically be set to each line of the file data.csv
# and will be different at each iteration of the loop
for line in data_file:
    # Create a list called columns, that contains the 4 elements of the row
    columns = line.rstrip().split(",")
    # assign the 0th column to the variable species
    species = columns[0]
    # assign the 1nd column to the variable name
    name = columns[1]
    # assign the 2st column to the variable sequence
    sequence = columns[2]
    # assign the 3rd column to the variable expression
    expression = columns[3]
    # This is an if condition that prints the contents of the variable name
    # if the name of the species is either Drosophila yakuba or
    # Drosophila ananassae
    if name=="Drosophila yakuba" or name=="Drosophila ananassae":
        print(name)

# Close file
data_file.close()

OUTPUT:

Please upvote if you like my answer and comment below if you have any queries or need any further explanation.

Add a comment
Know the answer?
Add Answer to:
Fill in the following code: # Open the file data.csv in read mode data_file = XXXXXX...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following code uses a Scanner object to read a text file called dogYears.txt. Notice that...

    The following code uses a Scanner object to read a text file called dogYears.txt. Notice that each line of this file contains a dog's name followed by an age. The program then outputs this data to the console. The output looks like this: Tippy 2 Rex 7 Desdemona 5 1. Your task is to use the Scanner methods that will initialize the variables name1, name2, name3, age1, age2, age3 so that the execution of the three println statements below will...

  • Could anyone help add to my python code? I now need to calculate the mean and...

    Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...

  • In this part, you will complete the code to solve a maze.

    - Complete the code to solve a maze- Discuss related data structures topicsProgramming-----------In this part, you will complete the code to solve a maze.Begin with the "solveMaze.py" starter file.This file contains comment instructions that tell you where to add your code.Each maze resides in a text file (with a .txt extension).The following symbols are used in the mazes:BARRIER = '-' # barrierFINISH = 'F' # finish (goal)OPEN = 'O' # open stepSTART = 'S' # start stepVISITED = '#' #...

  • Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such...

    Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such as declaration, initialization, storing, retrieving, and processing elements. • Effectively manipulating and using ArrayList objects. • Becoming familiar with the use of arrays as method arguments and how array elements are passed to and returned from the called method. • Mastering the use of various debugging tools available on the Eclipse IDU. Important: EVERY one of the following Activities MUST be in a separate...

  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT