python 用while求两数之间所有素数个数和总和
作者:野牛程序员:2023-12-21 13:17:34python阅读 2363
python 用while求两数之间所有素数个数和总和
def is_prime(num): if num < 2: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True start_number = int(input("请输入起始数字:")) end_number = int(input("请输入结束数字:")) current_number = start_number sum_primes = 0 count_primes = 0 while current_number <= end_number: if is_prime(current_number): sum_primes += current_number count_primes += 1 current_number += 1 print("素数个数为:", count_primes) print("素数总和为:", sum_primes)
野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892
- 上一篇:Python返回排序的素数
- 下一篇:python 列表排序求平均值