Answer to Question #303726 in Python for Reyad

Question #303726

Write a Python program that asks the user for a range (a starting number and an ending number) and then counts how many numbers are prime numbers and how many numbers are perfect numbers between that range. It also prints those numbers in the format shown in the output of the example given below.


Hint (1): We may declare two strings/lists to store the prime and perfect numbers. Inside the loop, we check for prime and perfect numbers and add them to respective string/list besides counting them.


Hint (2): We may need to convert numbers in String to integers for checking and calculations. We may again need to convert numbers to Strings for storing and printing as the outputs shown in the example below.


Example: If the user gives us a range of between 2 and 6, there are 3 prime numbers (2, 3, 5) and 1 perfect number (6) in that range.


Input:

2

6


Output:

Between 2 and 6,

Found 3 prime numbers

Found 1 perfect number

Prime numbers: 2, 3, 5

Perfect number: 6


1
Expert's answer
2022-02-28T01:08:27-0500
lower = 900
upper = 1000

print("Prime numbers between", lower, "and", upper, "are:")

for num in range(lower, upper + 1):
   if num > 1:
       for i in range(2, num):
           if (num % i) == 0:
               break
       else:
           print(num)

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