Python Programming Quiz Questions and Answers

Answer :
  • 27

Explanation :

A function is created to do a specific task. Often there is a result from such a task. The return keyword is used to return values from a function. A function may or may not return a value. If a function does not have a return keyword, it will send a none
Answer :
  • x, y and z

Explanation :

In the code shown above, x, y and z are global variables inside the function f. y and z are global because they are not assigned in the function. x is a global variable because it is explicitly specified so in the code. Hence, x, y and z are global variab
Answer :
  • list(reversed(l))

Explanation :

The built-in function reversed() can be used to reverse the elements of a list. This function accepts only an iterable as an argument. To print the output in the form of a list, we use: list(reversed(l)). The output will be: [4,3,2].
Answer :
  • Enter your input: Hello Python Received input is : Hello Python

Explanation :

The input([prompt]) function reads one line from standard input and returns it as a string. This would prompt you to enter any string and it would display same string on the screen. When I typed “Hello Python!”
Answer :
  • Built-in function & User defined function

Explanation :

Built-in functions and user defined ones. The built-in functions are part of the Python language. Examples are: dir(), len() or abs(). The user defined functions are functions created with the def keyword.
Answer :
  • Functions are reusable pieces of programs

Explanation :

Functions are reusable pieces of programs. They allow you to give a name to a block of statements, allowing you to run that block using the specified name anywhere in your program and any number of times.
Answer :
  • outer error

Explanation :

The error will be caused due to the statement f1(1) because the function is nested. If f1(1) had been called inside the function, the output would have been different and there would be no error.
Answer :
  • none of the above

Explanation :

Neither of 0.1, 0.2 and 0.3 can be represented accurately in binary. The round off errors from 0.1 and 0.2 accumulate and hence there is a difference of 5.5511e-17 between (0.1 + 0.2) and 0.3.
Answer :
  • a={5,6,7}

Explanation :

There exists add method for set data type. However 5 isn't added again as set consists of only non-duplicate elements and 5 already exists in the set. Execute in python shell to verify.
Answer :
  • 4 is maximum

Explanation :

Here, we define a function called printMax that uses two parameters called a and b. We find out the greater number using a simple if..else statement and then print the bigger number.