Answer to Question #228724 in Python for Raj

Question #228724
Want the full code of this question.
a company is planning a big sale at which they will give their customers a special promotional discount. each customer that purchases a product from the company has a unique customer id numbered from 0 to n-1.

1.andy, the marketing head of the company, has selected bill amounts of the n customers for the promotional scheme. the discount will be given to the customers whose bill amounts are perfect squares. the customers may use this discount on a future purchase. write an algorithm to help andy find the number of customers that will be given discounts?
1
Expert's answer
2021-08-23T07:29:11-0400


#Importing math library to check if a number is a perfect square
import math
def perfectSquare(x):
    root = math.sqrt(x)
    if int(root + 0.5) ** 2 == x:
        return 1
    else:
        return 0
        
        
        




uniqueCustomerId = [36, 16, 54, 81, 48, 49]
count = 0 
print("Input")
print("Unique customer id numbered from 0 to n-1.")
print(uniqueCustomerId)
print("Total number of customers are: "+str(len(uniqueCustomerId)) )
for uniqueId in uniqueCustomerId:
    if perfectSquare(uniqueId) == 1:
        count += 1
print("Output")
print(count)



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