In this task, you will get more practice writing, evaluating, and assigning expressions to variables in Python. In particular, we will explore lists and strings. Open IDLE and interact with the terminal to complete the following steps:
float
).[2,5,9]
to a variable called myList
. Write an expression that averages the elements of myList
."2 5 9"
to a variable called myString
. Using indexing, write an expression that just returns "2"
. Do the same for "5"
and "9"
.Consider the following Python program. The numbers to the left of the green line are just line references, and not part of the program; you wouldn't type them if you were writing this program yourself.
y = 10 x = y + 5 def addOne(t): y = t + 1 return y z = addOne(x) z y
Starting at Line 1, go through the program and write down the variable table (like we just did in class). What does z
output in Line 9? What does y
output in Line 10?