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)
d = input('Enter number range: ').split(' ')
sum = 0
if len(d) == 2:
a = d[0]; b = d[1]
if a.isdigit() and b.isdigit():
a = int(a); b = int(b)
if a < b:
for num in range(a, b+1):
sum += num
print('Sale =', sum)
else:
print('In a range, the second number must be greater than the first.')
else:
print('Wrong values')
else:
print('Wrong entry')
Comments
Leave a comment