Skip to content

Function in Python #24

Description

@josephbhardwaj301

def sayHello():
print("Hello")
print("Hello")
print("Hello")
print("Hello")
print("Hello")

def sayHelloNTimes(n):
for i in range(n):
print("Hello")

def sayMessageNTimes(message, n):
for i in range(n):
print(message)

def add(a, b):
return a + b

def high(a, b):
print(a, b)
if a >= b:
return a # Returns and ends the function
return b

def fact(n):
prod = 1
for i in range(2, n + 1):
prod *= i
return prod

def defaultParams(a=1, b=2, c=3):
print(a, b, c)

def unlimitedParams(*arg):
print(type(arg))
print(arg)

def unlimitedNamedParams(**arg):
print(type(arg))
print(arg)

unlimitedNamedParams(a=1, b=90, c="apple")

unlimitedParams()

unlimitedParams(1, 2, 3, 4, "apple", 3, 3)

x=sayMessageNTimes("Bye", 2)

print(x)

x = add(1, 2) # x=3

print(x)

x1 = 10

x2 = 23

x3 = 150

x = high(high(x1, x2), x3)

print(x)

for i in range(11):

x = fact(i)

print(i, x)

defaultParams()

defaultParams(6)

defaultParams(8,9)

defaultParams(c=90)

defaultParams(1,2,3,4)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions