Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
0 of .
Results for:
P. 1
Shootout

# Shootout

Ratings: (0)|Views: 8,275 |Likes:

### Availability:

See more
See less

07/31/2014

pdf

text

original

1
de
stringTimes (s ,n ):
””s
>
a string ,
>
an integersreturns a string that is made of n copies of sex : stringTimes ( hi ’ , 4)
>
hihihihi ””
2
de
countFives ( l ):
””returns the number of times the number 5 appears in l i s t ex : countFives ([5 , 3, 2, 4, 2, 5, 2, 4, 5, 6, 7])
>
””
3
de
listSum ( l ):
””calculates the sum of a l l the ints in l i s t l (assume a l l elements are ints )ex : listSum ([5 ,2 ,3])
>
10 ””
4
de
numTimes(word , sentence ):
””word
>
a string sentence
>
a string returns the number of times word appears in sentence .hint : turn sentence into a l i s t of words using s p l i ex : numtimes( the , it is the time of the season ’)
>
numtimes( happy , this sentence does not have the word in question ’)
>
””
5
de
countOdds( l ):
””
>
a l i s t of numbersreturns : the number of odd items in the l i s You can determine i f a number is odd or even using the mod operator
\
%.For example 5
\
%2 evaluates to 1 and 6
\
%2 evaluates to 0 ””
1