Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

1

def s t r i n g T i m e s ( s , n ) : s > a s t r i n g , n > an i n t e g e r s r e t u r n s a s t r i n g t h a t i s made o f n c o p i e s o f s ex : s t r i n g T i m e s ( h i , 4) > h i h i h i h i

2
def c o u n t F i v e s ( l ) : r e t u r n s t h e number o f t i m e s t h e number 5 a p p e a r s i n l i s t l ex : c o u n t F i v e s ( [ 5 , 3 , 2 , 4 , 2 , 5 , 2 , 4 , 5 , 6 , 7 ] ) > 3

3
def l i s t S u m ( l ) : c a l c u l a t e s t h e sum o f a l l t h e i n t s i n l i s t l ( assume a l l e l e m e n t s a r e i n t s ) ex : l i s t S u m ( [ 5 , 2 , 3 ] ) > 10

4
def numTimes ( word , s e n t e n c e ) : word > a s t r i n g s e n t e n c e > a s t r i n g r e t u r n s t h e number o f t i m e s word a p p e a r s i n s e n t e n c e . h i n t : t u r n s e n t e n c e i n t o a l i s t o f words u s i n g s p l i t ex : numtimes ( t h e , i t i s t h e time o f t h e s e a s o n ) > 2 numtimes ( happy , t h i s s e n t e n c e d o e s not have t h e word i n q u e s t i o n ) > 0

5
def countOdds ( l ) : l > a l i s t o f numbers r e t u r n s : t h e number o f odd i t e m s i n t h e l i s t You can d e t e r m i n e i f a number i s odd or even u s i n g t h e mod o p e r a t o r \%. For example 5\%2 e v a l u a t e s t o 1 and 6\%2 e v a l u a t e s t o 0

6
def capWords ( s e n t e n c e ) : s e n t e n c e >a s t r i n g . t h i s w i l l c r e a t e a new s t r i n g where t h e f i r s t l e t t e r o f e v e r y word has been c a p i t a l i z e d . You s h o u l d use s p l i t t o c o n v e r t t h e s t r i n g i n t o a l i s t , t h e n make a new l i s t t h a t c a p i t a l i z e s each l e t t e r , t h e n use j o i n t o c o n v e r t t h e new l i s t b a c k i n t o a s t r i n g .

7
def expand ( s ) : s > a s t r i n g t h e r o u t i n e w i l l r e t u r n a new s t r i n g such t h a t t h e f i r s t l e t t e r o f t h e new s t r i n g i s t h e f i r s t l e t t e r o f t h e o l d s t r i n g r e p e a t e d once , t h e second i s t h e second r e p e a t e d t w i c e , t h e t h i r d t h r e e times , e t c . Ex : expand ( abcde ) > a b b c c c d d d d e e e e e

You might also like