-5
I’m having trouble creating a program that asks the user for two values and prints all primes in that sequence (including the numbers typed)
Here comes the code:
number_range1=int(input('Digite o primeiro número do seu intervalo:'))
number_range2=int(input('Digite o segundo número do seu intervalo:'))
i=0
number=number_range1
numbers=[]
while i<=(number_range2-1):
numbers.append(number)
number=number+1
i+=1
i=1
k=0
r=0
primes=[]
j=len(numbers)
while k<j:
while i<=numbers[k]:
d=numbers[k]%i
if d==0:
r+=1
i+=1
if r==1 or r==2:
primes.append(numbers[k])
k+=1
print(primes)
The way it is, your code gives syntax error on line 4 due to the ```at the end of it. Are you sure that’s the code? Indentation is true to its original code?
– Woss
quote must have been an error in posting but the code is the same =/
– Nicolas Amad
Okay, so I recommend you try to do the table test explaining your code, because there are many snippets that do not make much sense and I imagine that it was not clear even for you, so the table test will help you understand your own code.
– Woss
And try to answer things like "why if I enter the values 10 and 20, the variable
numbers
from 10 to 29?"– Woss
thank you very much Woss
– Nicolas Amad