DEV Community

PERUMAL S
PERUMAL S

Posted on

Python Day-4 learning

Hi all

today we learned operators, conditions also we made simple calculator based on this function

codes

addition
Add=num1+num2

subtract
Add=num1-num2

multiple
Add=num1*num2

divide
Add=num1/num2

modules
Add=num1%num2

exponential
Add=num1**num2

loop (while)

if,elif,else Condition

*input method *
whatever put in inside of input it will converts as string

E.g
num1=input(enter a number)
if we want as valued number put use or convert as a int or Float

num1= int input(enter a number)

simple calculator code

while True:
print("simple calculator")
print("select operation")
print("1.add")
print("2.subtract")
print("3.multiply")
print("4.diveded")
print("5.modulas")
print("6.exponential")
choice=input("select operation 1/2/3/4/5/6/7:")
num1=float(input("enter a number 1:"))
num2=float(input("enter a number 2:"))
if choice== "1":
result = num1+num2
print("result is",result)
elif choice== "2":
result = num1-num2
print("result is",result)
elif choice== "3":
result = num1*num2
print("result is",result)
elif choice== "4":
result = num1/num2
print("result is",result)
elif choice== "5":
result = num1%num2
print("result is",result)
elif choice== "6":
result = num1**num2
print("result is",result)
else choice== "7":
break

Top comments (1)

Collapse
 
tshrinivasan profile image
Shrinivasan T

if, else section needs indentation.

check here
python.swaroopch.com/control_flow....