Create a file lists-again.py
in your cs100/ch4
folder.
numbers
so that it has 10 elements: the integers 1 through 10. Print it to verify it has those values. You should see in the shell:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
grades
so that it has 5 elements: the characters 'a'
, 'b'
, 'c'
, 'd'
, and 'e'
. Print it to verify it has those values. You should see in the shell:
['a', 'b', 'c', 'd', 'e']
prettyPrint_v1(myList)
that will iterate through the list parameter myList
to print each element at a new line. Call your function using grades
as an argument to test it – that is, call/invoke prettyPrint_v1(grades)
. It should output the following:
a
b
c
d
e
prettyPrint_v2(myList)
that will iterate through the list parameter myList
to print each element at a new line AND specify its index. Call your function using grades
as an argument to test it – that is, call/invoke prettyPrint_v2(grades)
. It should output the following:
index: 0 - value: a
index: 1 - value: b
index: 2 - value: c
index: 3 - value: d
index: 4 - value: e
listTimesTen(myList)
that will return a new list which consists of all values of myList
which have been multiplied by 10. For example, if we call print(listTimesTen(numbers))
, it will output the following:
[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
Hint: you will want to create an initially empty list otherList
, iterate through myList
, and append to otherList
the current item from myList
multiplied by 10. When finished, return otherList
.
stringToList(myString)
which takes a single parameter myString
and will output a list consisting of each individual character of the string. For example, if you call print(stringToList("example string"))
, it will output the following:
['e', 'x', 'a', 'm', 'p', 'l', 'e', ' ', 's', 't', 'r', 'i', 'n', 'g']
You are given a list of sensor readings [0.02, 0.03, 0.10, 0.12, 0.20]
. Write a function that takes one argument (a list), and subsequently filters out all values that are less than 0.05
and greater than 0.15
. Return the filtered list. Test your function by calling it.
forces1 = [2.3, 4.1, 6.0]
forces2 = [1.2, 3.5, 2.2]
print( elementadd(forces1, forces2) ) # results in [3.5, 7.6, 8.2]
repeat_v1(myList, number)
that takes two parameters: a list myList
and a positive integer number
. It will return a new list consisting of all items of myList
that are sequentially repeated number
times. For example, calling print(repeat_v1(['test', 'word', 'class'], 3))
will output the following:
['test', 'word', 'class', 'test', 'word', 'class', 'test', 'word', 'class']
repeat_v2(myList, number)
that takes two parameters: a list myList
and a positive integer number
. It will return a new list consisting of all items of myList
that are individually repeated number
times. For example, calling print(repeat_v2(['test', 'word', 'class'], 3))
will output the following:
['test', 'test', 'test', 'word', 'word', 'word', 'class', 'class', 'class']
[4, 8, 6, 5, 3, 7]
, which has a standard deviation of 1.87083.Submit your working python file to Moodle.