Question

In: Computer Science

write a Python program (with comments) to do the following: Define a list list1 = [['Rose',...

  1. write a Python program (with comments) to do the following:
    1. Define a list list1 = [['Rose', 'Daisy'], 7, 0, 5.5, [1, 22, 2.45, 3, 6, 5.8]] and print it.
    2. Print the length of list1 (i.e. number of items in list1) with a suitable message.
    3. Print the first character of the first string in the first item of list1 with a suitable message (HINT: The first item is the item with index 0).
    4. Print the sum of the last 4 numbers in the last element of list1, with a suitable message.
    5. Append the list ['apple', 'pear', 'grape'] to list1 and print the updated value of list1 with a suitable messag
    6. Save your code to a file with name lab4sol.py.
    7. Submit your Python code (i.e. lab4sol.py file) through BB.

Solutions

Expert Solution

list1 = [['Rose', 'Daisy'], 7, 0, 5.5, [1, 22, 2.45, 3, 6, 5.8]]

# printing the list

print (list1)

# printing the length of list by using len() funtion

print("number of items in list1 is:",len(list1))

#printing first char the first element of first list

print("The first item is the item with index 0 :",list1[0][0][0])

#printing the sum of last four elements in the list

print("The sum of the last four elements in the list1 :",list1[4][2]+list1[4][3]+list1[4][4]+list1[4][5])

# appending the list to list1

list1.append(['apple', 'pear', 'grape'])

print("final list1 after appending the list: ",list1)

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Write a Python program (with comments) to do the following: Assign the value '2+1' to a...
Write a Python program (with comments) to do the following: Assign the value '2+1' to a variable str1. Use the eval() function to evaluate str1and assign the result to a variable num1. Ask the user to input their birth month and assign it to a variable month and then print it with a suitable message. Determine the number of letters in month and display the result with a suitable message. Determine how many times the letter 'r ' occurs in...
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 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 Display the followings: All the numbers in numList The number of elements in numList The smallest number in numList The largest number in...
Write a program in Python language which will do the following: Write a program to prompt...
Write a program in Python language which will do the following: Write a program to prompt the user to enter a company name, city, state and zip code. Create a dictionary with the data. Output the dictionary. Then remove the city from the dictionary and output again.
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...
IN PYTHON Write a program to do the following: Solve the a set of equations as...
IN PYTHON Write a program to do the following: Solve the a set of equations as mentioned in "Zybook 5.20 LAB: Brute force equation solver". Instead of the arithmetic operators use your own function defined in a module named calc. You must provide two files (calc.py, brute_force_solver.py) :- 1) calc.py:- Add function named 'add' instead of using operator '+' [10pts] Add function named 'difference' instead of using operator '-' [10pts] Add function named 'product' instead of using operator '*' [10pts]...
for Python 3 Write a python program that Creates a list that has these values in...
for Python 3 Write a python program that Creates a list that has these values in this order, 'Python', 'JavaScript', and 'PHP' Define a displayMyClasses function that sorts the list and then displays each item on the list, one per line, in sorted order. Also, number the displayed list as shown in the "Running a Sample Program" shown below. Define a guessNext function that selects a random element from the list and returns it to the call of the function....
[PYTHON] How do you write a program that first gets a list of floating point numbers...
[PYTHON] How do you write a program that first gets a list of floating point numbers from input. The input begins with an integer indicating the number of numbers that follow. Then input all data values and store them in a list [PYTHON]
Please include comments on what you are doing.   Using linked lists, write a Python program that...
Please include comments on what you are doing.   Using linked lists, write a Python program that performs the following tasks: store the records for each college found in the input file - colleges.csv - into a linked list. (File includes name and state data fields) allow the user to search the linked list for a college’s name; display a message indicating whether or not the college’s name was in the database allow the user to enter a state's name and...
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...
write a python program to do the following: ask a student for 3 coefficients a b...
write a python program to do the following: ask a student for 3 coefficients a b c using the high_school_quizz to display the solutions of a quadratic problem. after, ask the student if he would like another quadratic equation solved If the student answers anything but yes, the program terminates by displaying a good bye message if the student answers yes (any form of yes should be acceptable) , the student is asked for the coefficient again and the resulting...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT