Question
Hello, please help me to answers my assignment I highly appreciate you effort. Thanks in advanced. 1.Which of the following lines properly starts a parameterless
Hello, please help me to answers my assignment I highly appreciate you effort. Thanks in advanced.
1.Which of the following lines properly starts a parameterless function definition?
a.) def fun(): b.) def fun: c.) function fun(): d.) fun function():
2. A function defined in the following way:
def function(x=0): return x a.) must be invoked with exactly one argument b.) may be invoked with any number of arguments (including zero) c.) may be invoked without any argument, or with just one d.) must be invoked without arguments
3. A built-in function is a function which:
a.) has to be imported before use b.) comes with Python, and is an integral part of Python c.) is hidden from programmers d.) has been placed within your code by another programmer
4. The fact that tuples belong to sequence types means:
a.) they can be extended using the .append() method b.) they can be indexed and sliced like lists c.) they can be modified using the del instruction d.) they are actually lists
5. What is the output of the following snippet?
def f(x): if x == 0: return 0 return x + f(x - 1) print(f(3))
a.) 3 b.) 1 c.) 6 d.) the code is erroneous
6. What is the output of the following snippet?
def fun(x): x += 1 return x x = 2 x = fun(x+1) print(x) a.) 3 b.) the code is erroneous c.) 5 d.) 4
7. What code would you insert into the commented line to obtain the output that reads:
a b c
Code:
dct = { } lst = ['a','b','c','d'] for i in range(len(lst) - 1): dct[lst[i]] = ( lst[i], ) for i in sorted(dct.keys()): k = dct[i] # insert your code
a.) print(k[0]) b.) print(k) c.) print(k['0']) d.) print(k["0"])
8. The following snippet:
def func(a,b): return a ** a print(func(2))
a.) is erroneous b.) will output 2 c.) will output 4 d.) will return None
9. The following snippet:
def func1(a): return a ** a def func2(a): return func1(a)*func1(a) print(func2(2)) a.) is erroneous b.) will output 4 c.) will output 2 d.) will output 16
10. Which of the following lines properly starts a function using two parameters, both with zeroed default values?
a.) def fun(a=b=0): b.) fun fun(a=0,b): c.) def fun(a=0,b=0): d.) fun fun(a,b=0):
11. Which of the following statements is false?
a.) The None value cannot be used as an argument of arithmetic operators b.) The None value can be compared with variables c.) The None value may not be used outside functions d.) The None value can be assigned to variables
12. What is the output of the following snippet?
def fun(x): if x % 2 == 0: return 1 else: return print(fun(fun(2)) + 1)
a.) 1 b.) 2 c.) None d.) the code will cause a runtime error
13. What is the output of the following snippet?
def fun(x): global y y = x * x return y fun(2) print(y)
a.) 4 b.) the code will cause a runtime error c.) 2 d.) None
14. What is the output of the following snippet?
def any(): print(var + 1,end='') var = 1 any() print(var) a.) 22 b.) 12 c.) 11 d.) 21
15.Assuming that tuple is a correctly created tuple, the fact that tuples are immutable means that the following instruction:
tuple[1] = tuple[1] + tuple[0]
a.) is illegal b.) is fully correct c.) can be executed if and only if the tuple contains at least two elements d.) may be illegal if the tuple contains strings
16. What is the output of the following snippet?
list = ['Mary', 'had', 'a', 'little', 'lamb'] def list(L): del L[3] L[3] = 'ram' print(list(list))
a.) ['Mary', 'had', 'a', 'lamb'] b.) ['Mary', 'had', 'a', 'little', 'lamb'] c.) the snippet is erroneous d.) ['Mary', 'had', 'a', 'ram']
17. What is the output of the following snippet?
def fun(x,y,z): return x+2*y+3*z print(fun(0,z=1,y=3)) a.) 0 b.) 9 c.) 3 d.) the snippet is erroneous
18. What is the output of the following snippet?
def fun(inp=2,out=3): return inp * out print(fun(out=2))
a.) the snippet is erroneous b.) 4 c.) 2 d.) 6
19. What is the output of the following snippet?
dct = { 'one':'two', 'three':'one', 'two':'three' } v = dct['one'] for k in range(len(dct)): v = dct[v] print(v)
a.) two b.) three c.) one d.) ('one', 'two', 'three')
20. What is the output of the following snippet?
tup = (1, 2, 4, 8) tup = tup[1:-1] tup = tup[0] print(tup)
a.) the snippet is erroneous b.) 2 c.) (2) d.) (2,)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started