PYTHON 2.7.13 Each function must be aswered RECURSIVELY, NO LOOPS ALLOWED 1. Wri
ID: 3789374 • Letter: P
Question
PYTHON 2.7.13
Each function must be aswered RECURSIVELY, NO LOOPS ALLOWED
1. Write a function called squares, which passed an integer n and returns the sqaures of each of the first n positive integers
def sqaures(n):
>>> square(5)
[1,4,9,16,25]
2. Write a function called acronym. This function is passed a string s, and returns a string consisting of all of the capitalized letters in s. For example:
def acronym(s):
>>> acronym('United States of America')
'USA'
>>> acronym('Depaul University')
'DPU'
>>> acronym('the University of Illinois at Chicago')
'UIC'
3. Write a function called is_prime. It is passed a parameter n and returns True is n is a prime number opr False otherwise. Recall that a number n is prime if only 1 and n divide evenly into n.
def is_prime(n, i=2)
> i is an optional parameter whose default value is 2
Explanation / Answer
def squares(n):
if(n==1):
return [1]
return squares(n-1)+[n*n]
print(squares(5))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.