Python outputs any two positive integers a and B, calculates the number of prime numbers in the interval [a, b], and outputs the last prime number.

CSDN Q & A 2022-05-14 15:47:17 阅读数:59


python Output any two positive integers a,b, Calculation interval 【a,b】 And output the last prime number . The problem of how to output the last prime number bothers me , I want to ask for your help .

Take the answer :
a = int(input('a:'))b = int(input('b:'))c = []for num in range(a,b+1): if num>1: for i in range(2,num): if (num%i)==0: break else: c.append(num)print(' Prime numbers :{}, the last one :{}'.format(len(c),max(c)))

版权声明:本文为[CSDN Q & A]所创,转载请带上原文链接,感谢。