Question

animals = ['cat','dog','fish'] print [animals] print (animals[0]): for animal in animals:                 print(animal) for id,animal in enumerate(animals):...

animals = ['cat','dog','fish']

print [animals]

print (animals[0]):

for animal in animals:

                print(animal)

for id,animal in enumerate(animals):

                print(id)

                print(animal)

animals.append('rabbit')

print (animals)

#print (animals.upper)

for animal in animals:

                print(animal.upper())

print ("You have " + str(len(animals))+" animals in your list.")

After the code executes, what is the index value for the last item in the list?

Homework Answers

Answer #1
animals = ['cat','dog','fish']
print (animals)

print (animals[0])
for animal in animals:

                print(animal)

for id,animal in enumerate(animals):

                print(id)

                print(animal)

animals.append('rabbit')

print (animals)

#print (animals.upper)

for animal in animals:

                print(animal.upper())

print ("You have " + str(len(animals))+" animals in your list.")

After the code executes, what is the index value for the last item in the list is 3

Know the answer?
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
Similar Questions
animals = ['cat','dog','fish'] print [animals] print (animals[0]): for animal in animals: print(animal) for id,animal in enumerate(animals):...
animals = ['cat','dog','fish'] print [animals] print (animals[0]): for animal in animals: print(animal) for id,animal in enumerate(animals): print(id) print(animal) animals.append('rabbit') print (animals) #print (animals.upper()) for animal in animals: print(animal.upper()) print ("You have " + str(len(animals))+" animals in your list.") What will print in the line #print(animals.upper())in code block A?
• Use this array: string[] pets = {"dog", "cat", "parakeet", "guinea pig", "dire rabbit", "hamster", "ferret",...
• Use this array: string[] pets = {"dog", "cat", "parakeet", "guinea pig", "dire rabbit", "hamster", "ferret", "velociraptor"}; • Using a for loop go through the array o Change the value of each element by adding an s to the end o Print out the index and the animal at that index  e.g. when counter = 2 I should see  pet at index 2 is parakeets • Using the foreach loop, print out the items of the array •...
convert this code to accept int value instead of float values using python. Make sure to...
convert this code to accept int value instead of float values using python. Make sure to follow the same code. do not change the steps and make sure to point to what code you replaced. make sure to have 2 files Method:----------------------- #define a python user difined method def get_float_val (prompt): is_num = False str_val = input (prompt) #prming read for our while #while is_num == False: (ignore this but it works) old school while not is_num: try: value =...
Using Python Assigns the value of “dog” to the variable AnimalName. Assigns the value of “pigeon”...
Using Python Assigns the value of “dog” to the variable AnimalName. Assigns the value of “pigeon” to the variable AltAnimal. Includes an if-statement in which… (Hint: You should use both elif and else.) If the value of AnimalName is “cat”, prints “The animal is a cat.” Includes a comment on the same line as this if-statement that explains what the if-statement is looking for (i.e., what would have to be true for the statement to return “true”). If the value...
a. Design a FSA that will recognize sentences such as “The dog that chased the cat...
a. Design a FSA that will recognize sentences such as “The dog that chased the cat that ate the mouse lived in the house that Jack built.” Namely, the sentences should look like “The ANIMAL1 that VERBED1 the ANIMAL2 that VERBED2 the ANIMAL3 … VERBED3 in the house that Jack built.”, where ANIMALn is an animal and VERBEDn is a past-tense verb, and where the maximum n can be arbitrarily large. Assume that words are fed to the FSA one...
please use linux/unix command terminal to complete, step 1 1-create a new directory named by inlab4...
please use linux/unix command terminal to complete, step 1 1-create a new directory named by inlab4 enter directory inlab4 create a new file named by reverse.c with the following contents and then close the file: /*reverse.c */ #include <stdio.h> reverse(char *before, char *after); main() { char str[100]; /*Buffer to hold reversed string */ reverse("cat", str); /*Reverse the string "cat" */ printf("reverse(\"cat\")=%s\n", str); /*Display result */ reverse("noon", str); /*Reverse the string "noon" */ printf("reverse(\"noon\")=%s\n", str); /*Display result */ } reverse(char *before,...
can you please do this lab? use lunix or C program its a continuation of a...
can you please do this lab? use lunix or C program its a continuation of a previous lab. the previous lab: Unix lab 4: compile and link multiple c or c++ files Please do the following tasks step by step: create a new directory named by inlab4 enter directory inlab4 create a new file named by reverse.c with the following contents and then close the file: /*reverse.c */ #include <stdio.h> reverse(char *before, char *after); main() {       char str[100];    /*Buffer...
1. What will the following python code display? num = list(range(5)) print(num) 2. Answer the following...
1. What will the following python code display? num = list(range(5)) print(num) 2. Answer the following questions using the list below. You can record your answers in the essay textbox. data = [5,3,7] A. Write code to replace the value in the 0 position with the number 8. B. Add the value 10 to the end of the list. C. Insert the value 22 after position 1 in the list. D. Remove the value at position 2. E. Sort the...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes and methods. Purpose: The purpose of this challenge is to provide experience creating a class and working with OO concepts in Python 3. Requirements: Write a class in Python 3 named Animal that has the following attributes and methods and is saved in the file Animal.py. Attributes __animal_type is a hidden attribute used to indicate the animal’s type. For example: gecko, walrus, tiger, etc....
convert code from python to cpp L = [2,7,4,19,45,16,9,13,8,69,55,11,23,98,14,5,1,3]   #Merging function def merge(M,N): merging_list = []...
convert code from python to cpp L = [2,7,4,19,45,16,9,13,8,69,55,11,23,98,14,5,1,3]   #Merging function def merge(M,N): merging_list = []        //create empty list to merge the lists M and N if not M:                //if M is empty list, m = 0                //set m = 0 else: m = len(M)             //otherwise, set m = len(M) if not N:                //if N is empty list, n = 0       ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT