7. If else statement & functions
7. If else statement & functions
A = 18
In [5]: if A>=35:
print("The Student is passed")
else:
print("The Student has failed")
In [4]: if A>=35:
print("The Student is passed")
else:
print("The Student has failed")
In [24]: a=60
In [25]: if a<35:
print("failed")
elif a>=35 and a<=60:
print("passed")
elif a>60 and a<=75:
print("first_class")
else:
print("the student is topper")
passed
In [33]: a= 350
In [34]: if a<=200:
print("cheap")
elif a>200 and a<=400:
print("affordable")
else:
print("expensive")
affordable
In [ ]: ### Functions
# write some logic (write it once) and use it multiple times
# function always starts with 'def' which means define
In [38]: greeting("sunil")
In [39]: greeting("anil")
In [44]: greeting("sunil")
In [45]: a=3
b=4
c=(a+b)
In [46]: print(c)
In [47]: a=5
b=7
c=(a*b)
In [48]: print(c)
35
In [50]: add(7,2)
In [51]: add(99,101)
200
In [53]: mul(3,4)
12
In [54]: mul(12,6)
72
In [ ]: #Mini Calculator
def subtraction(a,b):
c= a-b
print("the subtraction is: ",c)
def multiplication(a,b):
c= a*b
print("the multiplication is: ", c)
def division(a,b):
c=a/b
print("the division is: ", c)
File <string>:15
print("the division is: ", c)
^
IndentationError: unindent does not match any outer indentation level
In [8]: add(8,2)
Out[8]: 10
In [9]: sub(8,2)
Out[9]: 6
In [10]: mul(8,2)
Out[10]: 16
In [15]: div(8,2)
Out[15]: 4.0
if operation == "add":
addition(a,b)
elif operation =="sub":
subtraction(a,b)
elif operation =="mul":
multiplication(a,b)
elif operation =="div":
division(a,b)
In [ ]: