[ARCHIVED] Python program to print all Prime numbers in an Interval

Jump to solution
skshandilya33
Community Novice

def PrimeNumber_interval(start,end):
   print('prime number between %d and %d:'%(start,end))
   for i in range(start, end+1):
      for j in range(2,i):
         if i % j == 0:
               break
         else:
            print(i, end = ',')

PrimeNumber_interval(11,25)

output:  

  • prime number between 11 and 25: 11,13,17,19,23,

    NOte: Question is, i don't wanted to comma after 23 in output. How to solve it

Python program to print all Prime numbers in an Interval

Labels (2)
1 Solution
James
Community Champion

 @skshandilya33  

This sounds like a homework or exam question for a class.

We are a global community of users of the Canvas learning management system (the software you may use to take your online classes in). Your question has nothing to do with Canvas.

Many of us here are educators and will not knowingly answer what might be graded material for students. Similarly, we would expect our students to come to their instructor or use resources the instructor has allowed when doing problems, rather than posting the question in an online forum asking someone to solve the problem for you.

There are several ways to avoid the trailing comma and three approaches quickly come to my mind. I debated whether to even give a hint, but since this might be a quiz question where the teacher wants you to do it on your own, I do not feel that I even go as far as a hint.

View solution in original post

0 Likes