Python
Sample Output
>>> a = list(range(1, 6))
>>> a
[1, 2, 3, 4, 5]
>>> square(a)
>>> a
[1, 4, 9, 16, 25]
>>>
>>>
>>> b = list(range(1,6))
>>> squared(b)
[1, 4, 9, 16, 25]
>>> b
[1, 2, 3, 4, 5]
>>> c = squared(b)
>>> c
[1, 4, 9, 16, 25]
>>> b
[1, 2, 3, 4, 5]
>>>
>>>
>>> a = ["Kate", "and", "Allie", "spoke", "LOUDLY"]
>>> a
['Kate', 'and', 'Allie', 'spoke', 'LOUDLY']
>>> lowercase(a)
>>> a
['kate', 'and', 'allie', 'spoke', 'loudly']
>>>
>>>
>>> b = ["Kate", "and", "Allie", "spoke", "LOUDLY"]
>>> b
['Kate', 'and', 'Allie', 'spoke', 'LOUDLY']
>>> lowercased(b)
['kate', 'and', 'allie', 'spoke', 'loudly']
>>> b
['Kate', 'and', 'Allie', 'spoke', 'LOUDLY']
>>>
>>> c = lowercased(b)
>>> c
['kate', 'and', 'allie', 'spoke', 'loudly']
>>> b
['Kate', 'and', 'Allie', 'spoke', 'LOUDLY']
>>>
>>> p = Point(3,4)
>>> p
Point(3,4)
>>>
>>> str(p)
'(3,4)'
>>>
>>> print("p = {}".format(p))
p = (3,4)
>>>
>>>
>>> q = Point(3,4)
>>>
>>>
>>> p
Point(3,4)
>>> q
Point(3,4)
>>>
>>>
>>> p == q
True
>>>
>>>
>>> p is q
False
>>>
>>>
>>>
>>>
>>> r = Point(3,7)
>>> p
Point(3,4)
>>> r
Point(3,7)
>>>
>>> p == r
False
>>>
>>>
>>> p
Point(3,4)
>>> q
Point(3,4)
>>> r
Point(3,7)
>>>
>>> distance (p,q)
0.0
>>>
>>> distance(p,r)
3.0
>>>
>>>
>>> p
Point(3,4)
>>> double(p)
>>> p
Point(6,8)
>>>
>>>
>>> q
Point(3,4)
>>> doubled(q)
Point(6,8)
>>> q
Point(3,4)
>>> s = doubled(q)
>>>
>>> s
Point(6,8)
>>> q
Point(3,4)
>>>
>>> quit()def square(a):
for i in range(0, len(a)):#Loop through the list a
a[i] = a[i]*a[i]#Update element of list to its square
def squared(a):
b = []#Empty list
for i in range(0, len(a)):#Loop through the list a
b.append(a[i]*a[i])#Append to list b square of element in a
return b#Return new list
def lowercase(a):
for i in range(0, len(a)):#Loop through the list a
a[i] = a[i].lower()#Convert each string of list a to lowercase
def lowercased(a):
b = []#Empty list
for i in range(0, len(a)):#Loop through the list a
b.append(a[i].lower())#Append lowercase of each string of list a to list b
return b#Return new list
#Test square function
a = list(range(1, 6))
square(a)
print(a)
#Test squared function
b = list(range(6, 12))
c = squared(b)
print(c)
#Test lowercase function
d = ["Kate", "and", "Allie", "spoke", "LOUDLY"]
lowercase(d)
print(d)
#Test lowercased function
e = ["Kate", "and", "Allie", "spoke", "LOUDLY"]
f = lowercased(e)
print(f)
OUTPUT:
AS PER CHEGG'S POLICY ONLY FIRST 4 QUESTIONS WILL BE ANSWERED
Python Write a function square(a) that takes a list a of numbers and squares each of...
Python Write a move function that takes a list of tuples, where each tuple is an x-y-z coordinate pair. This function should update the original list in-place to shift/move/translate the coordinates by an x_move, y_move, and z_move (respectively) and return None.
PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number) and prints: My name is <name> and I am <age> years old(where name and age are the inputs) 2. Write a function that takes as input a and b and returns the result of: ??ab 3. Write a function that takes as input a and b and returns the result of: ??ab if it is valid to divide a and b 4. Write a...
Haskell Function program Write a function negateOdds that takes a list of integers and returns a list of integers with all of the odd integers negated. negateOdds :: [Integer] -> [Integer] example: [1,2,3,4,5] should return [-1,2,-3,4,-5]
Problem 1. Write a Python function times_i_at_odd(L) that takes as arguments a list L and returns a list consisting of the elements of L multiplied by the index number of the element at odd positions. (Use list comprehensions) >>> times_i_at_odd([1,2,3,4,5,6,7,8,9,10]) [2, 12, 30, 56, 90] Problem 2. Write a recursive function sum_cols(grid, n) that takes a list of lists of integers grid and integer n and returns the sum of column n in grid. For example, the call sum_cols([[1,2,3,4], [10,20,30,40],...
Python 3.0 Please Write a function that takes, as arguments, a binary string, a list of characters and the corresponding Huffman code for those characters. It decodes the binary string using the Huffman code, and returns the resulting decoded string. Name this function decodeStringHuffman(binaryString, myCharacters, myCode). For example, >>>decodeStringHuffman("1001100010111010101010111", ["A", "B", "C"], ["1", "00", "01"]) should return the string 'ABAABCCAACCCCCAA'
Write a function called most_consonants(words) that takes a list of strings called words and returns the string in the list with the most consonants (i.e., the most letters that are not vowels). You may assume that the strings only contain lowercase letters. For example: >>> most_consonants(['python', 'is', 'such', 'fun']) result: 'python' >>> most_consonants(['oooooooh', 'i', 'see', 'now']) result: 'now' The function that you write must use a helper function (either the num_vowels function from lecture, or a similar function that you...
Write the function deep_contains. It takes as input a number and a list. That list might contain lists as elements, and those lists might contain lists, etc. The deep_contains' function should return a Boolean indicating whether the number is contained inputted list, or a sublist of it, or a sublist of that, and so forth. For example: deep_contains (3, (1,3,5]) returns True deep_contains(3, 11, [3,5]]) returns True deep_contains (3, 1, [[3,4],5),6]) returns True deep_contains (2, (1,3,5]) returns False This function...
Write a function findEvens that takes an integer, n, as input and returns the list of even integers between 1 and n. Ex. Input: 10 Output: [2,4,6,8,10] Write a function sortList that takes in a list of strings and returns a list of those strings now sorted and lowercase. Ex. Input: [‘ABE’,’CAD’,’gaB’] Output: [‘abe’,’acd’,’abg’] Both done in Python
1 write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple. Hint (can be done in one pass, you are not allowed to use built-on min and max functions.)max, min = find_max_min(my_list):2 write a Python function that takes in a list of integers (elements), and an integer number (num). The functions should count and return number of integers in elements greater than, less than, and equal to...
Write a function called create_basic_pattern(background_colour, size) which takes a background colour code and an integer as parameters and returns a list of strings. The list represents the pattern of a pixel art pattern. For example, consider the following code fragment:pattern \(=\) create_basicThen the function should create a list of strings. The size of the list is 8 . Each element is a string with 8 'y' characters: