Q:

Create a function with default argument using python programming

belongs to collection: Python Functions Exercises

0

Create a function with default argument

Write a program to create a function show_employee() using the following conditions.

  • It should accept the employee’s name and salary and display both.
  • If the salary is missing in the function call then assign default value 9000 to salary

Given:

showEmployee("Ben", 12000)
showEmployee("Jessa")

Expected output:

Name: Ben salary: 12000
Name: Jessa salary: 9000

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Hint:

Default arguments take the default value during the function call if we do not pass them. We can assign a default value to an argument in function definition using the = assignment operator.

Solution:

# function with default argument
def show_employee(name, salary=9000):
    print("Name:", name, "salary:", salary)

show_employee("Ben", 12000)
show_employee("Jessa")

 

Explanation:

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Create an inner function to calculate the addition... >>
<< Write a python program to create function calculat...