Functions with parameters allow you to pass values when calling the function. These values are used inside the function to perform tasks.
Parameters वाली function में आप values को function को call करते समय भेज सकते हैं। ये values function के अंदर इस्तेमाल होती हैं।
def greet(name):
print("Hello,", name)
greet("Ankit")
Output:
Hello, Ankit
def add(a, b):
print("Sum:", a + b)
add(3, 7)
Output:
Sum: 10
def check_vote(age):
if age >= 18:
print("Eligible to vote")
else:
print("Not eligible")
check_vote(20)
Output:
Eligible to vote
def table(n):
for i in range(1, 11):
print(n, "x", i, "=", n*i)
table(6)
Output:
6 x 1 = 6 ... 6 x 10 = 60
def even_odd(n):
if n % 2 == 0:
print("Even")
else:
print("Odd")
even_odd(13)
Output:
Odd
def area(length, width):
print("Area:", length * width)
area(5, 4)
Output:
Area: 20
def maximum(a, b, c):
print("Max:", max(a, b, c))
maximum(5, 12, 9)
Output:
Max: 12
def interest(p, r, t):
si = (p * r * t) / 100
print("Simple Interest:", si)
interest(1000, 5, 2)
Output:
Simple Interest: 100.0
def student(name, roll):
print("Name:", name)
print("Roll No:", roll)
student("Ravi", 101)
Output:
Name: Ravi Roll No: 101
def stars(n):
print("*" * n)
stars(8)
Output:
********