For this assignment you will first figure out your answers in the Python shell. When you feel like you've arrived at the right answers, type them up in a single Python file and hand it in to the TAs. For some guidance on how to do this, see the Python homework instructions.
Enter the following assignment statement:
mylist = [4, 18, 13, 7]
mylist[1]
and mylist[2]
. Are they what you expected them to be? Remember that indices of a list start at 0, not 1.20
using only mathematical operators (+
,-
,*
,/
,(
,)
) and references to mylist
.10
using only mathematical operators and references to mylist
.mylist
using only mathematical operators and references to mylist
. Note that your answer is an integer, so it may not be exactly the precise numerical value you'd expect — we'll explore this further in Task 2.ourlist = [5, 6, 7, 8]
mylist
's value to [4, 5, 6, 7, 8]
, using only references to mylist
and ourlist
.Look at the following code:
numOfBertsToys = 10 stuffedAnimals = ['muffins', 'bonkers', 'grumpy', 'ed'] numberOfStuffies = len(stuffedAnimals) answer = numberOfStuffies / numOfBertsToys
answer
represent in terms of Bert's stuffed animals and his total number of toys?
answer
. Why is it 0? What would you change to get the correct value?
Consider the following assignment statements:
string1 = "Cookie Monster " string2 = "is hungry for a cookie. " string3 = "We'd better go to Meeting Street Cafe." stringlist = [string1, string2, string3]
stringlist[1]
?stringlist[1][:7]
(this one is a bit trickier)?stringlist
and the +
operator, write an expression that gives you two full sentences using the words in string1
, string2
, and string3
.string1
and string2
, indexing, and the +
operator, write an expression that evaluates to "Cookie Monster is hungry for cookies."
. Hint: how do you use indexing to pull out only one word, or only one letter, from a string?Rename your program YourName_HW2-1.py
and email it to cs0931handin@cs.brown.edu
.