Python 3 -Def Functions - How to Create a Def Function for 2 Input Numbers.
Tuesday, July 2, 2019
Add Comment
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.
- This task using a def function on python 3.
- There is a case where you have to input the first number and the second number.
- Then you are offered to choose one of the available options;
- addition
- subtraction
- multiplication
- division
- exit
- The options above are used to complete simple mathematical calculations.
- Here, the functions are used to calculate input numbers at the beginning.
- Now, try this code on your python editor.
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