In Python:
# Q1: create a list that has the following items.
# {1, 2 , 3 , 4 , 5}
# you need to start with an empty list. and then add the above components
# one by one.
MyList = [ #create an empty list, 1 point
MyList.-----(1) #add 1 to the list, 1 point
MyList.-----(2)
MyList.-----(3)
MyList.-----(4)
MyList.-----(5)
# now find the length of the list.
print(---(MyList)) # 1 point
# select the starting and ending point such that it shows 2,3,4
print(MyList[-:-]) # 1 point
# now, delet 1 from the list
--- MyList[-]# 1 point
# now, delete 3 from the list
MyList.---()# 1 pointScreenShot
-------------------------------------------
Program
#Create empty list
MyList=[]
#add values one by one
MyList.append(1)
MyList.append(2)
MyList.append(3)
MyList.append(4)
MyList.append(5)
#print list
print("My list is:",MyList)
#Find length of the list
listLength=len(MyList)
print("Length of the list:",listLength)
#Get elements other than start and end
print("Elements other than start and
end:",MyList[1:listLength-1])
#delete 1 from list
MyList.remove(1)
print("1 removed from the list:",MyList)
#delete 3 from list
MyList.remove(3)
print("3 removed from the list:",MyList)
---------------------------------
Output
My list is: [1, 2, 3, 4, 5]
Length of the list: 5
Elements other than start and end: [2, 3, 4]
1 removed from the list: [2, 3, 4, 5]
3 removed from the list: [2, 4, 5]
Press any key to continue . . .
In Python: # Q1: create a list that has the following items. # {1, 2 ,...
How to do this code?
HW13.11. Create an HTML list from a Python list The function below takes one parameter: a list, that contains only strings. Complete the function to create a unordered HTML list, as a string, and returns it. An empty list should return an empty HTML list with no list items. Do not add any extraneous whitespace to the HTML. For example, if given the list ["one", "two"], the function should return "<ul><li>one</li><li>two</li> </ul>". student.py IT TI...
3. Write Python statements that will do the following: a) Input a string from the user. *** Print meaningful messages along with your output.* b) Print the length of the String. Example input: The sky is blue. Correct output: The length of the string is 16 Incorrect output: 16 c) Print the first character of the string. d) Print the last character of the string. 4. Save the program. Double-check the left edge for syntax errors or warning symbols before...
Use python to code!
Q1 - You need to keep track of book titles. Write code using
function(s)
that will allow the user to do the following.
1. Add book titles to the list.
2. Delete book titles anywhere in the list by value.
3. Delete a book by position.
Note: if you wish to display
the booklist as a vertical number booklist , that is ok
(that is also a hint)
4. Insert book titles anywhere in the list....
Python
Lab 5. 3 Create a shopping list containing some items (strings). Prompt user for an item to be replaced by another item and the new item. Print the updated list.
I'm making a To-Do list in Python 2 and had the program running
before remembering that my professor wants me to put everything in
procedures. I can't seem to get it to work the way I have it now
and I can't figure it out. I commented out the lines that was
originally in the working program and added procedures to the top.
I've attached a screenshot of the error & pasted the code
below.
1 todo_list = []
2...
Which of the following is a valid definition of a list in Python? MyList = {1, 2, 3, 4} MyList = [1, 2, 3, 4] MyList = 1, 2, 3, 4 MyList = List(1, 2, 3, 4)
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...
Objective: Read in the names of several grocery items from the keyboard and create a shopping list using the Java ArrayList abstract data type. 1) Create a new empty ArrayList 2) Ask the user for 5 items to add to a shopping list and add them to the ArrayList (get from user via the keyboard). 3) Prompt the user for an item to search for on the list. Output a message to the user letting them know whether the item...
Write a few lines of Python that will do the following: - Create an empty list called all_numbers - Use a for loop to ask the user for 20 numbers (ints.). Add each number to all_numbers. - Use another loop to print each number in all_numbers that is between 10 an 20.
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.