sum = 0
num1 = int(input("Enter the first integer: "))
num2 = int(input("Enter the second integer: "))
def evenNums(num1,num2):
if num1%2==0 or num2%2==0:
sum+=1
return sum
elif num1%2==0 and num2%2==0:
sum+=2
return sum
else:
print evenNums(num1,num2)
Your code has several serious issues. Your “else” block is empty. Either delete that block or return something from that block. You cannot update “sum” in your function. You have to make the “sum” global. Like below
sum = 0
num1 = int(input("Enter the first integer: "))
num2 = int(input("Enter the second integer: "))
def evenNums(num1,num2):
global sum
if num1%2==0 or num2%2==0:
sum+=1
return sum
elif num1%2==0 and num2%2==0:
sum+=2
return sum
else:
return sum
print(evenNums(num1,num2))
Note: Using “global” in a code is not suggested or not a good practice. You may declare the sum inside the function like below
num1 = int(input("Enter the first integer: "))
num2 = int(input("Enter the second integer: "))
def evenNums(num1,num2):
sum = 0
if num1%2==0 or num2%2==0:
sum+=1
return sum
elif num1%2==0 and num2%2==0:
sum+=2
return sum
else:
return sum
print(evenNums(num1,num2))