Python 3 -Def Functions - How to Create a Def Function for 2 Input Numbers.

Python 3 -Def Functions - How to Create a Def Function for 2 Input Numbers.

Create a def function using 2 Input number. Below is an example of writing coding to input 2 numbers using the command function in python. 

Case.

  1. This task using a def function on python 3.
  2. There is a case where you have to input the first number and the second number.
  3. Then you are offered to choose one of the available options;
    • addition 
    • subtraction 
    • multiplication 
    • division 
    • exit
  4. The options above are used to complete simple mathematical calculations.
  5. Here, the functions are used to calculate input numbers at the beginning.
  6. Now, try this code on your python editor.
python def function input
python def function input

Python code.

def addition():
    print(a+b)
def subtraction():
    print(a-b)
def multiplication():
    print(a*b)
def division():
    print(a/b)
    
c=0    
while c!=5:
    a=int(input("Input a: "))
    b=int(input("Input b: "))

    print("=======================")
    print("1. addition")
    print("2. subtraction")
    print("3. multiplication")
    print("4. division")
    print("5. Exit")
    print("=======================")
    c=int(input("what will you do? select one of the options above :"))

    if c==5:
        break
    elif c<=0 :
        print("number not found")
    elif c==1:
        addition()
    elif c==2:
        subtraction()
    elif c==3:
        multiplication()
    elif c==4:
        division()  
    else:
        print("number not found")

0 Response to "Python 3 -Def Functions - How to Create a Def Function for 2 Input Numbers."

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel