Which of the following strings P is a Python program.
(b) P = “def f(x): x = 'am I a Python program?'”
(d) P = “def f(x,y,z): return y”
(e) P = “def f(x): return y”
For each of the following Python programs P and input strings I, give the output P(I),
(f) P = “def f(x): return str(len(x+x+'x'))”, I = “GAGAT”
(g) P = “def f(x): return str(len(x))”, I=P
(h) P = “def f(x): return str(1/int(x))”, I = “0”
b,d,e are all valid python programs
def f(x): x = 'am I a Python program?'
def a(x, y, z): return y
def g(x): return x
print(a(4, 5, 6))
print(g(4))
output:
f)
def f(x): return str(len(x+x+'x'))
print(f("GAGAT"))
# will return 11 because x+x+'x'= GAGATGAGATx and its length is 11
output:
g)
def f(x): return str(len(x))
print(f("def f(x): return str(len(x))"))
there are 28 characters in P
output:
h)
it will give runtime error as we doing 1/0 which is dividing by zero
Get Answers For Free
Most questions answered within 1 hours.