Questions: 5 831

Answers by our Experts: 5 728

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Write a function matched(s) that takes as input a string s and checks if the brackets "(" and ")" in s are matched: that is, every "(" has a matching ")" after it and every ")" has a matching "(" before it. Your function should ignore all other symbols that appear in s. Your function should return True if s has matched brackets and False if it does not.

Here are some examples to show how your function should work.


>>> matched("zb%78")
True
>>> matched("(7)(a")
False
>>> matched("a)*(?")
False
>>> matched("((jkl)78(A)&l(8(dd(FJI:),):)?)")
True
Write a function intreverse(n) that takes as input a positive integer n and returns the integer obtained by reversing the digits in n.

Here are some examples of how your function should work.

>>> intreverse(783)
387
>>> intreverse(242789)
987242
>>> intreverse(3)
3
Consider the following function f.

def f(m):
if m==0:
return(0)
else:
return(m+f(m-1))

Which one of the following is correct?
1)The function always terminates with f(n)=n(n+1)/2
2)The function always terminates with f(n)=factorial of n
3)The function terminates for non-negative n with f(n)=n(n+1)/2
4)The function terminates for non-negative n with f(n)=factorial of n
Write a function intreverse(n) that takes as input a positive integer n and returns the integer obtained by reversing the digits in n.

Here are some examples of how your function should work.

>>> intreverse(783)
387
>>> intreverse(242789)
987242
>>> intreverse(3)
3
def h(m,n):
ans = 0
while (m >= n):
(ans,m) = (ans+1,m-n)
return(ans)
Consider the following function f.
def f(m):
if m == 0:
return(0)
else:
return(m+f(m-1))
Which of the following is correct?
The function always terminates with f(n) = n(n+1)/2
The function always terminates with f(n) = factorial of n
The function terminates for non-negative n with f(n) = n(n+1)/2
The function terminates for non-negative n with f(n) = factorial of n
What does g(31415927) return, for the following function definition?
def g(x):
(q,d) = (1,0)
while q <= x:
(q,d) = (q*10,d+1)
return(d)
What does g(31415927) return, for the following function definition?
def g(x):
(q,d) = (1,0)
while q <= x:
(q,d) = (q*10,d+1)
return(d)
What does g(31415927) return, for the following function definition?
def g(x):
(q,d) = (1,0)
while q <= x:
(q,d) = (q*10,d+1)
return(d)
Consider the following function h.
def h(n):
f = 0
for i in range(1,n+1):
if n%i == 0:
f = f + 1
return(f%2 == 1)
The function h(n) given above returns True for a positive number n whenever:
n is a multiple of 2
n is a composite number
n is a prime number
n is a perfect square
LATEST TUTORIALS
APPROVED BY CLIENTS