A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Create a function with default argument using python programming
Q:

Create a function with default argument using python programming

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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now