Answer to Question #302126 in Python for aman

Question #302126

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)

1
Expert's answer
2022-02-24T08:03:14-0500
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')

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