Functions & Scope · Question 1 · Easy

A canteen bill function has two default parameters. What does this code print when one call skips qty by using a keyword argument?

def bill(price, qty=1, tax=0):
    return price * qty + tax

print(bill(50, tax=5), bill(50, 2))
  1. 55 105
  2. 250 100
  3. 55 100
  4. TypeError
Answer and explanation

Answer: C. 55 100

Explanation: In bill(50, tax=5) qty keeps its default 1, so the result is 50 × 1 + 5 = 55. In bill(50, 2) the 2 goes to qty and tax stays 0, giving 100.

Next: The greet function below prints a message but has no return statement. What…

Practise functions & scope

Try a fresh set of functions & scope questions with an explanation after every answer, free and without signing up: Functions & Scope practice. Or sit a full placement mock test.

More functions & scope questions

More python practice

Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge