Just began using python (have almost 0 clue)

Just began using python (have almost 0 clue)

31°
Img 20141222 wa0003
Deal Subedar
108
1662
15

def calculator(num1,num2,operator):
result = 0
if operator==“+”:
result=num1+num2
elif operator==“-”:
result=abs(num1-num2)
elif operator==“*”:
result=num1*num2
elif operator==“/”:
result= num1/num2
else:
print(“\n Invalid operator chosen”)
return result
print(“\n Welcome to calculator”)
print(“\n Enter two numbers followed by the operator”)
num1= input(“Enter number one”)
num2= input(“Enter number two”)
operator= input(“\n Enter operator”)
print(calculator(num1,num2,operator))

IF anyone knows python could they guide me where did I go wrong since I was trying basic stuff like making a calculator using function and return statement

6 Comments  |  
5 Dimers
Img 20190610 wa0008
Deal Cadet
78
189
13

What error you are getting??

Missing
Deal Newbie
50
20
0

def calculator(num1,num2,operator):
result = 0
if operator==‘+’:
result=num1+num2
elif operator==‘-’:
result=abs(num1-num2)
elif operator==‘*’:
result=num1*num2
elif operator==‘/’:
result= num1/num2
else:
print(‘\n Invalid operator chosen’)
return result
print(‘\n Welcome to calculator’)
print(‘\n Enter two numbers followed by the operator’)
num1= int(input(‘Enter number one’))
num2= int(input(‘Enter number two’))
operator= input(‘\n Enter operator’)
print(calculator(num1,num2,operator))

Missing
Deal Newbie
50
20
0

num1= int(input(‘Enter number one’))
num2= int(input(‘Enter number two’))
here you have to write int otherwise it take string type input

Img 20141222 wa0003
Deal Subedar
108
1662
15

Thankyou and the other problem I had was I couldn’t understand the difference between range vs xrange…

Missing