Question

Consider the list myList: myList = ["a", "America", "1", [5,3,9], "3", ["Mercy"]] #1 1) The Python...

Consider the list myList: myList = ["a", "America", "1", [5,3,9], "3", ["Mercy"]]

#1 1) The Python statement __________________ returns a

#2 2) The Python statement __________________ returns America

#3 3) The Python statement __________________ returns Ame

#4 The type of the third element is _______.

#6 The Python statement __________________ returns the following:

['Mercy']

#7 The python statement temp = _______ converts the third element to integer and assigns the result to temp.

#8 Consider the fourth element of myList and let it be called myList[3].

The python statement _______ checks to see if the first element of myList[3].

#9 Now we want to sort (descending order) the contents in the fourth element of myList.

A Python statement __________________ inserts the second element of myList[3] into the first position of myList.

#10 pop out the last element of myList[3].

#11 myList has a nest list at the end. Code a Python segment to convert it to an element.

Note that all the contents should remain the same. Fill in the blanks. myList._________ (myList.___________)

#12 in myList, write a code segment. If the third element is bigger than the fifth element, their multiplication will be appended to myList.

Otherwise, their addition will be extended as a nested list to myList. Note that if type conversion is needed, please do so in your coding list.

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

main.py saved 1 mylist = [a, America, 1, (5,3,9], 3, [Mercy]] America Ame <class str> [Mercy] 3 _returns a #1 1

main.py E saved 25 #8 Consider the fourth element of myList and let it be called myList[3]. 26 # The python statement checks

code:

myList = ["a", "America", "1", [5,3,9], "3", ["Mercy"]]

#1 1) The Python statement __________________ returns a

#a is at index 0 so we can print it by

print(myList[0])

#2 2) The Python statement __________________ returns America

print(myList[1])

#3 3) The Python statement __________________ returns Ame

#we have to return first 3 chars of america

print(myList[1][:3])

#4 The type of the third element is _______.

#3rd element is at index 2

print(type(myList[2]))

#6 The Python statement __________________ returns the following: ['Mercy']

print(myList[5])

#7 The python statement temp = _______ converts the third element to integer and assigns the result to temp.

temp = int(myList[2])

print(temp)

#8 Consider the fourth element of myList and let it be called myList[3].

# The python statement _______ checks to see if the first element of myList[3].

print(myList[3][0])

#9 Now we want to sort (descending order) the contents in the fourth element of myList.

# A Python statement __________________ inserts the second element of myList[3] into the first position of myList.

#we can swap the items by

myList[3][0], myList[3][1] = myList[3][1], myList[3][0]

print(myList[3])

#10 pop out the last element of myList[3].

print(myList[3].pop())

#11 myList has a nest list at the end. Code a Python segment to convert it to an element.

# Note that all the contents should remain the same. Fill in the blanks. myList._________ (myList.___________)

myList.append(myList.pop()[0])

print(myList)

#12 in myList, write a code segment. If the third element is bigger than the fifth element, their multiplication will be appended to myList.

#Otherwise, their addition will be extended as a nested list to myList. Note that if type conversion is needed, please do so in your coding list.

if int(myList[2]) > int(myList[4]):

myList.append(int(myList[2]) * int(myList[4]))

else:

myList.append(int(myList[2]) + int(myList[4]))

print(myList)


Add a comment
Know the answer?
Add Answer to:
Consider the list myList: myList = ["a", "America", "1", [5,3,9], "3", ["Mercy"]] #1 1) The Python...
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
  • require python 5. You have the following list stored in variable myList [ 3, 7, -1,...

    require python 5. You have the following list stored in variable myList [ 3, 7, -1, 2, -10, 6, 8) i. Write a program that creates a new list, with the same numbers as mylist, apart from any negative numbers, which should be removed. Although you are using mylist as an example, it should work for any list of numbers. ii. Now adjust your program so that instead of deleting them, any negative numbers are replaced with a zero.

  • Python Given a list like myList = [1, 2, 3, 4]. Your task is to find...

    Python Given a list like myList = [1, 2, 3, 4]. Your task is to find sum of each number with another number. For example, 1+2+1+3+1+4,2+3,2+4,3+4. Use for loop to accomplish this task. Return Output: 1 + 2 1 + 3 1 + 4 2 + 3 2 + 4 3 + 4 The sum value: 30

  • PYTHON Define a function reverseNestedList(...) which receives one possibly nested list (lst1) and returns the reverse...

    PYTHON Define a function reverseNestedList(...) which receives one possibly nested list (lst1) and returns the reverse of both the given list and any nested lists inside it. Note that the testing inputs will not include lists that are nested more than twice (a list in a list in a list ++...) [[[...],1], 1] Good luck! As an example, the following code fragment: lst1 = [[1, 2], [3, 4]] print(reverseNestedList(lst1)) should produce the output: [[4, 3], [2, 1]]

  • 1) Which of the following is NOT true about a Python variable? a) A Python variable...

    1) Which of the following is NOT true about a Python variable? a) A Python variable must have a value b) A Python variable can be deleted c) The lifetime of a Python variable is the whole duration of a program execution.   d) A Python variable can have the value None.        2) Given the code segment:        What is the result of executing the code segment? a) Syntax error b) Runtime error c) No error      d) Logic error 3) What...

  • When using Python 3 lists {fill in the blank}. A. ! a negative lookup (such as...

    When using Python 3 lists {fill in the blank}. A. ! a negative lookup (such as `somelist[-3]`) refers to list values positioned relative to the end of the list B. a copy of the list contents is made as the result of a statement such as `some_other_list = somelist` C. ! we can refer to the list from the second element to the end using `somelist[1:]` D. Python 3 ensures all values within the same list have the same type...

  • Python: 1) Consider the following code segment: try : inputFile = open("lyrics.txt", "r") line = inputFile.readline()...

    Python: 1) Consider the following code segment: try : inputFile = open("lyrics.txt", "r") line = inputFile.readline() print(line) _____________________ print("Error") What should be placed in the blank so that the program will print Error instead of crashing if an exception occurs while opening or reading from the file? Group of answer choices a- except RuntimeError : b- except EnvironmentError : c- except IOError : d- except IndexError : 2) Consider the following code segment: line = "hello world!" parts = line.split()...

  • a7q3.cc File #include <iostream> #include <cstring> #include "ArrayList.h" using namespace std; // Algorithm copy(s) // Pre:...

    a7q3.cc File #include <iostream> #include <cstring> #include "ArrayList.h" using namespace std; // Algorithm copy(s) // Pre: s :: refToChar // Post: memory allocated on heap to store a copy // Return: reference to new string char *copy(char *s) { char *temp = new char[strlen(s)+1]; strcpy(temp,s); return temp; } void test_ListOperations(){    cout << "testing createList" << endl;    List *myList = createList(10);    if (myList == NULL){ cout << "createList failed" << endl; return; } else{ cout << "createList succeeded"...

  • Hi, I need help writing a code for this. The language is python 3, and we...

    Hi, I need help writing a code for this. The language is python 3, and we cannot use things like break, continue, exit(), lambda, map, filter, raise, try, except, and assert in our code. Thank you! Implement one of the sorting algorithms from class, either bubble, selection or quick sort with the following modification. Call the function "color_sort(the_list)" Each element is now a list (or tuple) with two elements. The first element is the number value that you need to...

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • Hello can anyone help solve this please in Python the way it's asked? Question 22 40 pts List Comprehensions Write...

    Hello can anyone help solve this please in Python the way it's asked? Question 22 40 pts List Comprehensions Write the solution to a file named p2.py and upload it here. Comprehensions will show up at the midterm exam, so it's important to practice. a) Write a list comprehension that returns a list [0, 1,4, 9, 16, .. 625] starting from range(0, 26). (lots of list elements were omitted in ...) b) Write a list comprehension that returns the list...

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