Answer to Question #292688 in Python for Pradeep

Question #292688

write a programm to print hard if any carry in addition of two given numbers otherwise print easy.


1
Expert's answer
2022-02-01T12:34:12-0500
def carry(a, b):
	carry = 0
	count = 0
	len_a = len(a)
	len_b = len(b)


	while (len_a != 0 or len_b != 0):
		x = 0
		y = 0
		if (len_a > 0):
			x = int(a[len_a - 1]) + int('0');
			len_a -= 1
		
		if (len_b > 0):
			y = int(b[len_b - 1]) + int('0');
			len_b -= 1
		sum = x + y + carry;
		if (sum >= 10):
			carry = 1
			count += 1


		else:
			carry = 0
	if count == 0:
	    return "Easy"
	else:
	    return "Hard"


a = input()
b = input()


print(carry(a,b))




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS