-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWeek-1
More file actions
41 lines (31 loc) · 726 Bytes
/
Week-1
File metadata and controls
41 lines (31 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
WEEK ! QUIZ:
1) What does h(19685) return for the following function definition?
def h(x):
(d,n) = (1,0)
while d <= x:
(d,n) = (d*3,n+1)
return(n)
ANS: 10
2) What is g(36) - g(35), given the definition of g below?
def g(n):
s=0
for i in range(2,n):
if n%i == 0:
s = s+1
return(s)
ANS: 5
3) Consider the following function f.
def f(n):
s=0
for i in range(1,n+1):
if n//i == i and n%i == 0:
s = 1
return(s%2 == 1)
ANS: n is a perfect square.
4) Consider the following function fpp.
def foo(m):
if m == 0:
return(0)
else:
return(m+foo(m-1))
ANS: The function terminates for nonnegative n with f(n) = n(n+1)/2