Dev.to WebDev πŸ›  Dev πŸ‘ 0

Using def Function Practice Programs in Python

1) def painter(): print("painting") painter() // painting 2) Create a function called add(),sub(), and get the input for a and b inside every function then print the result. def add(): a=int(input("

1)

def painter():
    print("painting")


painter()
//
painting

2) Create a function called add(),sub(), and get the input for a and b inside every function then print the result.

def add():
    a=int(input("enter a"))
    b=int(input("enter b"))
    print(a+b)
    print("ok")

add()
//
enter a 10
enter b 20
30
ok
def sub():
    print("subtraction")
    a=int(input("enter a"))
    b=int(input("enter b"))
    print(a-b)


sub()
//
subtraction
enter a 30
enter b 20
10

3) Get a integer number from user and pass it to the function called findevenorodd().Let the function print whether the number is even or odd.

def findevenorodd(a):
    if (a%2==0):
        print("even")
    else:
        print("odd")


findevenorodd(10)
even

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.