Question: im working on a pylint test for my basic calculator and i and one pylint error left which says. 'Either all return statements in a

im working on a pylint test for my basic calculator and i and one pylint error left which says. 'Either all return statements in a function should return an expression, or none of them should.' and i cant seem to fix it ive been at it for an hour
this is my code:
'''making a calculator that output add/sub/mul/div'''
def calculator(num1, operator, num2):
'''Perform a calculation based on two numbers and a given operator.'''
try:
num1= float(num1)
num2= float(num2)
if operator =='+':
return num1+ num2
if operator =='-':
return num1- num2
if operator =='*':
return num1* num2
if operator =='/':
if num2!=0:
return num1/ num2
return "Cannot divide by zero"
except ValueError:
return "Invalid input"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!