Answer to Question #226869 in Python for jayanth

Question #226869

an ecommerce website wishes to find the lucky customer who will be eligible for full value cashback. for this purpose, a number n is fed to the system. it will return another number that is calculated by an algorithm. in an algorithm, a sequence is generated, in which each number is the sum of the two preceding numbers. initially, the sequence will have two 1's in it. the system will return the nth number from the generated sequence which is treated as the order id. the lucky customer will be the one who has placed that order. write an algorithm to help the website find the lucky customer.


1
Expert's answer
2021-08-17T15:50:31-0400
def lucky_customer(n):
	if n <= 2:
		return 1
	curr_num = 1
	prew_num = 1
	k = 2
	while n > k:
		curr_num, prew_num = curr_num + prew_num, curr_num
		k += 1
	return curr_num


# test
print('order id :', lucky_customer(int(input('n = '))))

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