Just began using python (have almost 0 clue)

# Just began using python (have almost 0 clue)

31°
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

5 Dimers
78
189
13

What error you are getting??

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))

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

Deal Lieutenant
93
4974
100

you are not converting num1 and num2 to int before passing them to calculator method.
ref: https://ideone.com/...e4

Deal Subedar
108
1662
15

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