A company is offering a special discount to its customers based on an algorithm. Two range values are fed to the algorithm and in return t will calculate the discount to offer to the customers. The discount is calculated as the sum of all the prime numbers within the defined range including the range values if the range values are the prime numbers
Write an algorithm to find the special discount given to the customers
Input
The first line of the input consists of
an integer-rangelet remeng
the minimum boundary wabererte
given range finding the p
values)
'''
A company is offering a special discount to its customers based on an algorithm.
Two range values are fed to the algorithm and in return t will calculate the
discount to offer to the customers. The discount is calculated as the sum of all
the prime numbers within the defined range including the range values if the range
values are the prime numbers
Write an algorithm to find the special discount given to the customers
` Input The first line of the input consists of an integer-range let remeng
the minimum boundary wabererte given range finding the p values)
'''
def is_prime(n):
Flag=1
if n <=1:
Flag=0
else:
for i in range(2, n):
if n % i == 0:
Flag=0
if(n==2): Flag=0
return(Flag)
a = int(input("Enter lower range: "))
b = int(input("Enter upper range: "))
Discount=0
P=[]
for r in range(a,b+1):
if(is_prime(r)==1):
Discount = Discount+r
P.append(r)
print("All prime numbers in range from (",a," to ",b,") are ",P)
print("Total Discount = ",Discount)
Comments
Leave a comment