【发布时间】:2019-10-10 13:57:51
【问题描述】:
我需要打印一个范围内的所有素数。但输出必须像 1 行一样,由于某种原因,我不能使用 list 或 .append 甚至 .join。
例如,范围是 8 到 20,输出将是:"The prime number(s) in this range are 11, 13, 17, 19
我现在的代码是:
start_range = int(input("Enter the first number in the range"))
end_range = int(input("Enter the number in the end of the range"))
for integer in range(start_range, end_range + 1):
count = 0
for prime in range(2, integer+1):#This loop is from part 1 and will tell if the number is prime or not
if (integer % prime) == 0:
count = count + 1
if count > 2 and count != 1:
break
else:
print("The prime number(s) in this range are", integer)
【问题讨论】:
标签: python count numbers output python-3.7