Prime Number Program In Tcl
>>>>I am trying to write a program that will figure out if a number is prime >>or not. Currently this is the code that I have: >>[code cut] >>Hi Andrade1, >>As in your other previous homework programs, you seem to have some trouble >with control flow. Have you considered talking with your professor or >teaching assistant about this? >>>>import math >>>>def main(): >>number=input('Please enter a positive whole number greater than 2: >>') >>for value in range(2, number-math. Crack Vertus Fluid Mask 3.0.10. sqrt): >>if number% value == 0: >>print number, 'is not prime' >>exit >>print number, 'is prime' >>>>main() >>>>my problem is that the output prints both statements whether the number >>is prime or not.
Download Prime number program. Output of program: Remember two is the only even and the smallest prime number. Visual Basic .net 2008 Tutorial Pdf more. First few prime numbers are 2, 3, 5, 7, 11, 13, 17. Prime numbers have many applications in computer science and mathematics. A number greater than one can be factorized into prime numbers, for example, 540 = 2 2 *3 3 *5 1.
>>>The block of code: >>###### >for value in range(2, number-math.sqrt): >if number% value == 0: >print number, 'is not prime' >exit >###### >>has two issues. What is 'exit'? Instead of exit I can use break so that the loop will stop executing >2.
What is 'number - math.sqrt'? For math.sqrt I could use math. Tibia Maps 8.54. sqrt(n) so that it would take the sqrt of n which is entered in by the user However for the output I am still receiving enter a number greater than 2: 49 49 is prime 49 is prime 49 is prime 49 is prime 49 is prime 49 is not prime >Instead of 'exit', you may be looking for the 'return' statement instead. >>>Good luck to you. >>Recent Messages in this Thread.