5) WAP to accept two numbers and do the following:
(5)
a. If the larger is even and the smaller is odd, subtract smaller from the larger and
subtract 1 from the answer. Display it.
b. If the larger is odd and the smaller is even, add the larger and smaller no.s and add 1
to the final answer. Display it
Answers
Answered by
1
Answer:
a.
num1=eval(input("enter 1st number:"))
num2=eval(input("enter 2nd number:"))
if num1>num2:
if num1%2==0 and num2%2==1:
ans=(num1-num2)-1
print("answer is",ans)
else:
print("entry is not valid.")
elif num2>num1:
if num2%2==0 and num1%2==1:
ans=(num2-num1)-1
print("answer is",ans)
else:
print("entry is not valid.")
else:
print("entry is not valid.")
b.
num1=eval(input("enter 1st number:"))
num2=eval(input("enter 2nd number:"))
if num1>num2:
if num2%2==0 and num1%2==1:
ans=(num1+num2)+1
print("answer is",ans)
else:
print("entry is not valid.")
elif num2>num1:
if num1%2==0 and num2%2==1:
ans=(num1+num2)+1
print("answer is",ans)
else:
print("entry is not valid.")
else:
print("entry is not valid.")
Similar questions