Question

1/ What results would be appear on the computer screen after the print statements in the...

1/ What results would be appear on the computer screen after the print statements in the following Python code? Explain what is happening in lines 4-6.

  1. animals = ["cat", "dog", "elephant", "fox", ["mouse", "bird", "beetle"]]
  2. newlist = animals
  3. print( newlist)
  4. newlist[4][0] = ["caterpillar", "butterfly"]
  5. print(newlist)
  6. print(animals)

2/ What is the result of the following Python statements:

  1. print( animals[2:4])                    
  1. print(animals[-3] )

output = "fox"

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

1.

Animals =["cat", "Dog","Elephant","fox,["mouse","bird","beetle"]]

Here Animals is a nested list having another list at index 4.

Let us see index of all the elements of the list animals

Animals[0] = "Cat"

Animals[1] = "dog"

Animals[2] = "elephant"

Animals[3] = " fox"

Animals[4][0] = "mouse"

Animals[4][1] ="bird"

Animals[4][2] = "beetle"

// Further we are copying our list:Animals to a new list:Newlist //

In the line 4 ....

Newlist[4][0] = ["caterpillar","butterfly"]

// .......... Here we are modifing the existing element of Newlist at the index [4][0] which was mouse

So now the index of the elements are

Newlist [4][0][0] = " caterpillar "

Newlist[4][0][1] = " butterfly " ...........//

Print(newlist) // displaying all the elements of Newlist //

Print(animals) // displaying all the elements of animals //

2.

Print(Animals[2:4])

// .........it defines and then display the range of the index of the elements which the user wants to display , including the element of 2nd element and excluding the 4th element ] .......//

Output = [ "Elephant " , "fox"]

Print (Animals [-3])

//....... It displays the third last element of the list Animal .....//

So it displays fox

Output = ["fox"]

Add a comment
Know the answer?
Add Answer to:
1/ What results would be appear on the computer screen after the print statements in the...
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
  • Question 1 The code used to output messages to the screen begins with run # print...

    Question 1 The code used to output messages to the screen begins with run # print output Flag this Question Question 2 The code used to begin a comment in the Python program source code is # Hello * Comment Flag this Question Question 3 A variable name is like a(n) input typed on a keyboard address in computer memory where values can be stored output to a computer screen value assigned to an address in computer memory Flag this...

  • 10q I need help this is a python language For the following question, refer to the...

    10q I need help this is a python language For the following question, refer to the Python module on the right, as well as the name of the file that contains each module. 1) What is the output of the following code?. import animals alist = [animals.cat('Garfield'), animals.Dog('odie'), animals. Fox ('Nicholas P. wilde'), animals. Animal ('Judy Hopps')] File animals.py class Animal: def _init__(self, name): self.name = name def getName(self): return self.name for a in alist: print( a.getName() + ', '...

  • 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...

  • What will be the output after the following statements? in python programming a = [-3, -1,...

    What will be the output after the following statements? in python programming a = [-3, -1, 0, 1, 3] print([abs(x) for x in a]):  

  • Provide the expected output AS IT WOULD APPEAR IN A JAVA PROGRAM as the result of a print statement. (i.e. Enter true or...

    Provide the expected output AS IT WOULD APPEAR IN A JAVA PROGRAM as the result of a print statement. (i.e. Enter true or false (all lower case letters). If you enter TRUE, F, True, etc these will be marked wrong). Given the following declarations: int x = 25; int y = -4; int z = 17; boolean b = false; What would be the output of the following Boolean expressions? (x % 2 != 0) && b b && !b...

  • LAFEXERCİSE Biological Classification, Primate Features Date Of the array of varied creatures within the kingdom Animalia, some fy, some crawl, some leap, and some swim. This exercise ask...

    LAFEXERCİSE Biological Classification, Primate Features Date Of the array of varied creatures within the kingdom Animalia, some fy, some crawl, some leap, and some swim. This exercise asks you to place a number of them into taxonomic groups and decide which groups are related most closely to which other groups. Work with a lab partners) on this exencise Dog sull for other nonprimate skul Skull of monkcy or ape Start with a small sample to work with first, consisting of...

  • MAKE SURE OUTPUT 4 IS CORRECT - Python PROBLEM: A useful computer utility is to report...

    MAKE SURE OUTPUT 4 IS CORRECT - Python PROBLEM: A useful computer utility is to report the differences between two files. In this program, you will compare two strings to find common strings. For this program, a string consists of "words"; words are letters which are separated by a single space. The following algorithm will be used first: Consider each word in turn from left to right in the first string. If that word appears as a word or part...

  • Problem 1 1 def modify(word.ch). word == word + ch return word print('new word is', word)...

    Problem 1 1 def modify(word.ch). word == word + ch return word print('new word is', word) To run the function modify() defined above, we make the following call: result = modify('course', 's') Find and fix the errors in the function definition, lines (1) to (4), such that after the call is executed: • Variable result has the value 'courses' • 'new word is courses' is printed out. For each error found and fixed, you must indicate the following: • line...

  • The goal of this homework is to write a small database system for an Animal Shelter....

    The goal of this homework is to write a small database system for an Animal Shelter. This is a no-kill shelter like the one just west of the Addition Airport. You will accept animal “donations” to the shelter, but mostly only dogs and cats. (But yes, there may be the occasional hamster or other nondog, non-cat animal donation.) At present, all we need to do is write the skeleton of a database that will track all the animals in the...

  • Which of the following statements would be most likely to appear in a professional association’s code...

    Which of the following statements would be most likely to appear in a professional association’s code of ethics for its members?   I will maintain the confidentiality of my username and password.   I will keep my personal knowledge up-to-date and insure that proper expertise is available when needed.   I will be use organizational supplies for official purposes only.   I will use my network account only for the purpose specified in my job description. Question 2 How is “risk” defined in the...

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