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.
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
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
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