Table of Contents
hide
Example : A Function program in Python to show Default Parameter.
def msg(name="World"):
return f"Hello, {name}!"
print(msg()) # Output: Hello, World! Default Parameter.
print(msg("India")) # Output: Hello, India!
NB: Here, the default value is 'World'. When the parameter value is not supplied to the function then default value works.
Example : A Function program in Python to show the Addition result of two user-accepted values.
x=int(input("Enter first value ="))
y=int(input("Enter second value ="))
def Addition():
z=x+y
print("The addition result is = ",z)
Addition()
Output:
Enter first value =10
Enter second value =20
The addition result is = 30
------------ OR ------------
def Addition():
x=int(input("Enter first value = "))
y=int(input("Enter second value = "))
z=x+y
print("The addition result is = ",z)
Addition()
Output:
Enter first value = 10
Enter second value = 20
The addition result is = 30
Example : A Function program in Python to show the accepted single value is Odd or Even.
def Addition():
x=int(input("Enter first value = "))
if x%2==0:
print("Value is Even")
else:
print("Value is Odd")
Addition()
Output:
Enter first value = 20
Value is Even
Example : A Function program in Python to show the table’s values of accepted single value.
def Addition():
x=int(input("Enter table value = "))
k=x
for i in range(x,k*10+1,k):
print(i,end=" ")
Addition()
Output:
Enter table value = 7
7 14 21 28 35 42 49 56 63 70
------------- OR -------------
def Addition():
x=int(input("Enter table value = "))
k=x
while x<=k*10:
print(x,end=" ")
x=x+k
Addition()
Output:
Enter table value = 7
7 14 21 28 35 42 49 56 63 70
0 Comments