# Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

## Python User define Function, How to create a function in the python program:-

### Functionname()

Example of User define a function to calculate addition and subtraction:-

a = int(input("enter first number"))
b = int(input("enter second number"))
c = a+b
print(c)

def substraction():
a = int(input("enter first number"))
b = int(input("enter second number"))
c = a-b
print(c)

substraction()

Another example of a User define a function to calculate Simple Interest:-

def calculatesi():
p = float(input("enter value for amount"))
r = float(input("enter value for rate"))
t = float(input("enter value for time"))
si = (p*r*t)/100
print("result is ",si)

calculatesi()

### Assignment of default function:-

1)  WAP to reverse a five-digit number using the no return type function.

2) WAP to perform addition of complex number using return type function

3)  WAP to create a salary calculator using no return type function

4)  WAP to calculate compound interest using no return type function.

2) Parametrised:-

### Assignment of Parametrised function in Python:-

1) WAP to create a mark sheet program using function takes the dictionary as an input variable

### 2)  Create an ATM Program using a function?

If you have any doubt in programming or join online classes then you can contact us by comment .

1. #WAP to reverse a five-digit number using no return type function.
def reverse():#define a function
num=int(input("enter any 5-digit number"))
for i in range(0,5):
i=num%10
num=num//10
print(i)
reverse()#calling a function

2. #WAP to perform addition of complex number using return type function
def complex():
a=2+3j
b=4+5j

return a+b
res=complex()
print(res)

3. #WAP to create a salary calculator using no return type function
def salary():
name=input("enter name of employee")
basic=float(input("enter basic salary"))
da=float(10*basic)/100
hra=float(15*basic)/100
pf=float(5*basic)/100
ta=float(8.5*basic)/100
perday=float(basic/30)
netpay=float(basic+hra+ta+da-(2*perday))
grosspay=float(netpay-pf)
print(grosspay)
salary()

4. # WAP to calculate compound interest using no return type function.
def compoundinterest():
p=float(input("enter value of p"))
r=float(input("enter value of r"))
t=float(input("enter value of n"))
Amount = p * (pow((1 + r / 100), t))
CI = Amount - p
print("Compound interest is", CI)
compoundinterest()

5. #WAP to calculate Simple Interest where rate and time will be constant and
#the principal will be an integer? (by using function)
def simpleinterest():
p=int(input("enter principle amount"))
const=(2,4)
SI=p*const*const

print(SI)
simpleinterest()

6. #WAP to calculate the area of a triangle, circle, and rectangle in the same program where the value of pi, the base of the triangle, and the height of the rectangle will be constant.
def traingle():
H=int(input("enter value of H"))
const=(2,0)
area=(const*H)/2
print(area)
def circle():
const=(3.14,0)
area=(const*r*r)
print(area)
def rectangle():
B=int(input("enter value of base"))
const=(3,0)
area=(const*B)
print(area)
traingle()
circle()
rectangle()

7. #WAP to convert temperature from Celsius to Fahrenheit?
def temp():
c=int(input("enter temprature in celsius"))
f=((9*c)+160)/5
print(f)
temp()

8. #WAP to swap two numbers without using a third variable by using function
def swap():
a=int(input("enter value of a"))
b=int(input("enter value of b"))
print("before swappine",a,b)
a,b=b,a
print("after swapping",a,b)
swap()

9. #WAP to calculate square and cube of any entered number(by using function)
def square():
a=int(input("enter value of a"))
sqr=a*a
print(sqr)
def cube():
b=int(input("enter value of b"))
cub=b*b*b
print(cub)

cube()
square()

10. sir this program not run properly is it right logic or not
# Create ATM Program using function ?

balance=float(input("enter balance"))

print(name,"welcome to our bank")
print("\n 1-debit,\n 2-credit,\n 3-viewbalance,\n 4-exit")
def debit():
print("enter amount that you want to withdraw",amount)
balance=balance-amount
def credit():
print("enter amount that you want deposit",amount)
balance=balance+amount
def showbalance():
print("total balance is",balance)

def ATM():
flag=False
PIN=1234

for i in range(1,4):
p=int(input("enter 4 digit pin number"))
if p==PIN:
flag=True
print(flag)
break
else:
print("pin is incorrect and number of attempt is attempted")
while(True):
print("\n 1-debit,\n 2-credit,\n 3-viewbalance,\n 4-exit")
if select==1:
print("name","amount to withdraw",debit())
if select==2:
print("name","amount to withdraw",credit())
if select==3:
print("name","amount to withdraw",showbalance())
if select==4:
print("name","amount to withdraw",exit())
called by
import atm
atm.ATM()
debit.atm()
credit.atm()
showbalance.atm()

11. #sir not run properly is it right logic for function
def marksheet(dict):
dict={"phy":60,"eng":40,"res":90,"hindi":40,"maths":50}
count=0
gm=0
s=""
dist=""
for i in dict:
if dict[i]>=0 and dict[i]<=100:
print(dict[i])
if dict[i]<33:
count=count+1
s=s+i+ " "
gm=dict[i]
else:
if dict[i]>=75:
dist = dist+ i + " "
else:
print("All subject marks should be 0 to 100")
break

total=total+marks[i]
else:
if count==0 or(count==1 and gm>=29):
per= total/5
if per>33 and per<45:
print("Third division with {0} %".format(per))
elif per<60:
print("Second division with {0} %".format(per))
else:
print("First division with {0} %".format(per))

if gm>0:
print("You are pass by grace and grace marks is ",str(33-gm), "grace subject is ",s)
if dist!=0:
print("Distinction subject name is ",dist)

elif count==1:
print("suppl in ",s)
else:
print("fail in ",s)

marksheet(dict)