Answer to Question #302233 in Python for Abcd

Question #302233

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

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

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