Question

In: Computer Science

Write a Python program that performs the following list operations. Part A Define a list called...

Write a Python program that performs the following list operations.

Part A

  1. Define a list called numList with elements.

84, 94, 27, 74, 19, 90, 16, 21, 56, 50, 77, 59, 41, 63, 18, 26, 80, 74, 57, 30, 40, 93, 70, 28, 14, 11, 43,65, 91, 83, 22, 53, 74, 44, 73, 55, 47, 74, 81

  1. Display the followings:
    • All the numbers in numList
    • The number of elements in numList
    • The smallest number in numList
    • The largest number in numList
    • The sum of all the numbers in numList
    • The number of times 74 appears in numList

Part B

  1. Define an empty list called dogNames and display it.

  2. Add the following names to dogNames and display all the names in the dogNames list.

Max, Lola, Buddy, Coco, Teddy

  1. Display all the names in the dogNames list after each of the following updates.

    • Add the name ‘Benji’ at the end of the dogNames list.
    • Add the name ‘Chico’ at the beginning of the dogNames list (as the first element).
    • Add the name ‘Nala’ after the name ‘Coco’.
    • Add the name ‘Mimi’ before the name ‘Buddy’.
  2. Define another list called catNames with elements and display all the names in catNames list.

Kitty, Simba, Shadow, Coco, Pepper, Tiger

  1. Create a new list called petNames by joining the dogNames and catName list. Note that in petNames list, all the dog names come before the cat names. Display all the names in petNames list.

  2. Display the followings using petNames list.

    • The total number of names in petNames.
    • The number of times the name ‘Coco’ appears in petNames.
    • The index of the pet name ‘Coco’ in petNames.
    • The first pet name that appears in chronological order based on Unicode. Hint:Use min function.
    • The last pet name that appears in chronological order based on Unicode. Hint: Use max function.
  3. Delete the last name in petNames list and display both the deleted name and the updated petName list.

  4. Delete the first name in petNames list and display both the deleted name and the updated petName list.

  5. Delete the first occurrence of the pet name ‘Coco’ using the remove() method and the deleted name and the updated petName list.

  6. In a comment, explain the reason to get None as the deleted name in your output for part 9.

Solutions

Expert Solution

Part A:

numList=[84, 94, 27, 74, 19, 90, 16, 21, 56, 50, 77, 59, 41, 63, 18, 26, 80, 74, 57, 30, 40, 93, 70, 28, 14, 11, 43,65, 91, 83, 22, 53, 74, 44, 73, 55, 47, 74, 81]
print("List is:",numList)
print("Numer of elements:",len(numList))
print("smallest number is:",min(numList))
print("Largest number is:",max(numList))
print("Sum of all elements is:",sum(numList))
print("Number of times 74 appears is:",numList.count(74))

Part B:

dogNames=[]
print("List is:",dogNames)
dogNames.append("Max")
dogNames.append("Lola")
dogNames.append("Buddy")
dogNames.append("Coco")
dogNames.append("Teddy")
print("List is:",dogNames)
dogNames.append("Benji")
dogNames.insert(0,"Chico")
dogNames.insert(dogNames.index("Coco")+1,"Nala")
dogNames.insert(dogNames.index("Buddy")-1,"Mimi")
print("List is:",dogNames)

catNames=[]
catNames.append("Kitty")
catNames.append("Simba")
catNames.append("Shadow")
catNames.append("Coco")
catNames.append("Pepper")
catNames.append("Tiger")
print("List is:",catNames)

petNames=[]
petNames=dogNames+catNames
print("List is:",petNames)
print("Total number of Names is:",len(petNames))
print("Number of times Coco appears is :",petNames.count("Coco"))
print("Index of pet Coco is:",petNames.index("Coco"))
print("The first pet that appears in chronological order is:",min(petNames))
print("The last pet that appears in chronological order is:",max(petNames))
print("The deleted pet name is:",petNames[-1])
petNames.remove(petNames[-1])
print("List is:",petNames)
print("The deleted pet name is:",petNames[0])
petNames.remove(petNames[0])
print("List is:",petNames)
petNames.remove("Coco")
print("List is:",petNames)

Screenshots:

The screenshots are attached below for reference.

Please follow them for output.

Please upvote my answer. Thank you.

Note:

Please see that as per the guidelines, we are allowed to answer maximum upto one question posted in a single question.

In case of multiple choice type questions, upto 4 questions cn be answered.


Related Solutions

Using Python, write a program that meets the following requirements: Make a list called sandwich_orders and...
Using Python, write a program that meets the following requirements: Make a list called sandwich_orders and fill it with the names of various sandwiches. Make an empty list called finished_sandwiches. Loop through the list of sandwich orders and spring a message for each order such as "I am working on your tuna sandwich" As each sandwich is made, move it to the list of finished sandwiches. After all the sandwiches have been made, print a message listing each sandwich that...
1. Write a Python program that performs the following: 2. Defines an array of integers from...
1. Write a Python program that performs the following: 2. Defines an array of integers from 1 to 10. The numbers should be filled automatically without the need for user inputs 3. Find the sum of the numbers that are divisible by 3 (i.e., when a number is divided by 3, the remainder is zero) 4. Swap the positions of the maximum and minimum elements in the array. First, you need to find the maximum element as shown in the...
Write a program in python such that There exists a list of emails List Ls =...
Write a program in python such that There exists a list of emails List Ls = ['[email protected]','[email protected]','[email protected]','[email protected]',[email protected]'] Count the number of emails IDS which ends in "ac.in" Write proper program with proper function accepting the argument list of emails and function should print the number of email IDs and also the email IDS ending with ac.in output 2 [email protected] [email protected] ================================= i am trying like this but getting confused len [True for x in Ls if x.endswith('.ac.in')] please write complete...
Use Python program. Make a list called groceries with the following values: "pineapple", "tangerine", and "peach"....
Use Python program. Make a list called groceries with the following values: "pineapple", "tangerine", and "peach". Define these two dictionaries in your program: stock = {     "pineapple": 6,     "peach": 0,     "tangerine": 32,     "pear": 15 } prices = {     "pineapple": 4,     "peach": 2,     "tangerine": 1.5,     "pear": 3 } Take one argument “item” as input from the user and returns the cost of that item. Assume the user will only input an item that...
Write a python program using the following requirements: Create a class called Sentence which has a...
Write a python program using the following requirements: Create a class called Sentence which has a constructor that takes a sentence string as input. The default value for the constructor should be an empty string The sentence must be a private attribute in the class contains the following class methods: get_all_words — Returns all the words in the sentence as a list get_word — Returns only the word at a particular index in the sentence Arguments: index set_word — Changes...
Using Python, write a program named hw3a.py that meets the following requirements: Create a dictionary called...
Using Python, write a program named hw3a.py that meets the following requirements: Create a dictionary called glossary. Have the glossary include a list of five (5) programing words you have learned in chapters 4-6. Use these words as keys to your dictionary. Find the definition of these words and use them as the values to the keys. Using a loop, print each word and its meaning as neatly formatted output. Create three dictionaries called person. Have each of the person...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
Using LIST and FUNCTION Write a program in Python that asks for the names of three...
Using LIST and FUNCTION Write a program in Python that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place.
use python 1. Write a program that a. defines a list of countries that are members...
use python 1. Write a program that a. defines a list of countries that are members of BRICS (Brazil, Russia, India, China, Sri Lanka) b. Check whether a country is a member of BRICS or not Program run Enter the name of country: Pakistan Pakistan is not a member of BRICS Enter the name of country : India India is a member of BRICS 2. Write a program to create a list of numbers in the range of 1 to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT