Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

22. What is the output of this code? def foo(fname, val): print(fname(val)) foo(

ID: 3600624 • Letter: 2

Question

22. What is the output of this code? def foo(fname, val): print(fname(val)) foo(max, I1,2, 3].) foo(min, [1, 2, 3) b. 1 3 c. Error d. none of the mentioned 23. What is the output of this code? total def fooO: total += 1 return total print(foo)) c. error d. none of the mentioned 24. To open a file c:Iscores.txt for writing, we use a. Op c. d. outfile = open("c:scores.txt", "w") outfile = open("c:llscores.txt". “w") outfile = open(file = "ciscores.txt","w") outfihe = open(file-"c:Wscores.txt", "w') 25. The primary difference between a tuple and a list is that a. you don't use commas to separate elements in a tuple b. a tuple can only include string elements c. a tuple cannot include lists as elements d once a tuple is created, it cannot be changed

Explanation / Answer

22.option(a)

3

1

Explanation: from given set of elements [1,2,3] max value is 3

thus foo(max,[1,2,3]) returns 3

from given set of elements [1,2,3] min value is 1

thus foo(min,[1,2,3]) returns 1

so answer is 3

1

23.option(c)error

Explanation:

total=0 #this total is outer scope
def foo():
total +=1 #it gives error as "local variable ' total' referenced before assignment
return total
print(foo())

so we get the error as "local variable ' total' referenced before assignment "

so if we give total within th scope of foo

def foo():

total=0 //within the scope
total +=1
return total
print(foo()) //it gives result 1

24.option(b)outfile = open(“c:\scores.txt”, “w”)

Explanation:w is used to indicate that file is to be written to

25. option(d)once a tuple is created, it cannot be changed

Explanation: a list is mutable, which means that a program can change its contents.
a tuple is immutable, which means that once it is created, its contents cannot be changed.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote