Report Bug

Qus

What will be the output of the following Python code?

  x = 5   def f1():      global x      x = 4  def f2(a,b):      global x      return a+b+x  f1()  total = f2(1,2)  print(total)
Qusनिम्नलिखित Python कोड का आउटपुट क्या होगा?


A. Error
B. 7
C. 8
D. 15


Solution
B. 7



Explanation
In the code shown above, the variable ‘x’ has been declared as a global variable under both the functions f1 and f2. The value returned is a+b+x = 1+2+4 = 7.
CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad