Sep-30-2019, 12:32 PM
Hello,
I have a slight problem with my prime number checking machine :D It does not print out the number 2 it should and does falsely recognize 9 as a prime. This is a homework for a course and the assignment goes beyond this, but I cannot continue before I have solved this problem since we are using a virtual platform.
I'm from Finland so the text is in Finnish, but I tried to include comments for clarification.
Problems:
- does not print out number 2
- falsely recognizes 9 as a prime
Thanks for any help you can give!
I have a slight problem with my prime number checking machine :D It does not print out the number 2 it should and does falsely recognize 9 as a prime. This is a homework for a course and the assignment goes beyond this, but I cannot continue before I have solved this problem since we are using a virtual platform.
I'm from Finland so the text is in Finnish, but I tried to include comments for clarification.
Problems:
- does not print out number 2
- falsely recognizes 9 as a prime
Thanks for any help you can give!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
low = int ( input ( "Anna alueen alaraja: " )) # range low end high = int ( input ( "Anna alueen yläraja: " )) # range high end for num in range (low,high + 1 ): if (num = = 0 ) or (num = = 1 ): print (num, "ei ole kelvollinen alkuluku." ) # 0 and 1 are not valid primes elif (num ! = 0 ) or (num ! = 1 ): for div in range ( 2 ,num): # testing whether a prime or not if ((num % div) = = 0 ): print (num, "ei ole alkuluku, koska" ,div, "*" ,num / / div, "=" ,num) # number is not a prime because ... break else : print (num, "on alkuluku." ) # number is prime number break area = len ( range (low,high + 1 )) # How many numbers in range print ( "Tutkittiin" ,area, "lukua" ) # How many numbers chekced by program print ( "Kiitos ohjelman käytöstä." ) # Thanks |