DEV Community

Ezhil Abinaya K
Ezhil Abinaya K

Posted on

Using def Function Practice Programs in Python

1)

def painter():
    print("painting")


painter()
//
painting
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

Top comments (0)