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
myList = [1, 2, 3, 4]
total = 0
for i in range(len(myList)):
for j in range(i + 1, len(myList)):
print(myList[i], '+', myList[j])
total += (myList[i] + myList[j])
print("\nThe sum value:", total)

Python Given a list like myList = [1, 2, 3, 4]. Your task is to find...
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...
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)
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.
Sc Python 1 Task 2 3 Consider a binary tree of N vertices 4 such that children of node K are 2* K + 1. Vertex 1 is the root Kand 2 of the tree and each node has an integer value associated with it. Such a tree may be represented as an array of N integers by writing down values from consecutive nodes For example, the tree below 8 Test might be represented as an array o A node...
Part 1: Using Idle Write a Python Script that Does the Following 1. At the top of your program, import the math library as in from math import * to make the functions in the math module available. Create a variable and assign into it a constant positive integer number of your choice. The number should be at most 10. 1 Suppose we call this variable x for this writeup document Try something like x = 4 2. Create another...
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...
python List1=[ ["a", 1], ["b", 3], ["c", 3], ["d", 2], ["e", 1], ["f", 4], ["g", 2]] 1 def function(Letter,List),example, function("c",List) return 3 2 def function(word,List),example, function("a",List) return 1, function("be",List) return 4, function("bee",[b,5],[e,20]) return 45 Dictionary = ["a","bee","ad","ae"] 3 ["a","b","y","e"] return[["a",1],["ae",2],["bee",5]] 4 input a list, find largest value words can spell, return words and value dont using loop, using recursion for those code
Task 1: 1. Write a generic class named MyList, with a type parameter T. The type parameter T should be constrained to an upper bound: the Number class. The class should have as a field an ArrayList of type T. Write the class constructor to create the ArrayList. 2. Write a public method named add, which accepts a parameter of type T. When an argument is passed to the method, add it to the ArrayList. 3. Write a public method...
PYTHON LANGUAGE Task 11 -Create a list with 5 items having 3 distinct data types -output the second element of the list -output the last element of the list using -negative index -positive index -len method Task 12 -Create a list with 3 items -add an item to the end of the list -remove the first item of the list -determine if an item exists in the list -if it does, display its index -if it does not, give user...
Task 1: String with Loop • Write a program that reads a sentence and use a loop that counts how many elements in a string that are equal to ‘t’. Task 2: List with Function • Write a function fill that fills all elements of a list with a given value. • For example: o The call fill(scores, 13) should fill all elements of the list scores with the value 13. • Write a demo program to show how this...