Welcome to TRiBot Forums

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Sign in to follow this  
Followers 0


6 posts in this topic

so im doing a project for csc104(programming in python) .. and I have to write a program that does three things. (1) find the sqrt of a num that's inputted using the newton-raphson method -- done -- (2) identify and determine whether or not the number is prime and print it, and (3) identify and print its factors. the third part should be fairly simple,.. atm, im having issues verifying part (2) but my code seems to be close.


## (1)
a=eval(input("Please enter an integer: "))
i = 0

while i < 100:
  dividend = x + (a / x)
  y= dividend/2
  i = i + 1
  if i is 99:
## (2)
y=list(range(2, x))
#using list(y) to verify my range2,x; it will be removed
while i <= len(y):
  while i < len(y):
    if a/y[i] == int(a/y[i]):
      print(aa + " is not prime. ")
      i = len(y)
  if i == len(y) and a/y[i] == int(a/y[i]):
      print(aa + " is not prime. ")
    print(aa + " is prime. ")
  i= i + 1


Share this post

Link to post
Share on other sites

Here is a simple way to find a prime. Just iterate through the numbers from 2 to the square root of the number your checking.

import math

num = input('Please enter an integer: ')

is_prime = True
for i in range(2, int(math.sqrt(num)) + 1):
    if num % i == 0:
        is_prime = False

if is_prime:
    print('{} is prime'.format(num))
    print('{} is not prime'.format(num))


Share this post

Link to post
Share on other sites
public static boolean isPrime(Integer n) {
  if(n < 1) return false;
  if(n <= 3) return true;
  if(n % 2 == 0) return false;
  Double toCount = Math.sqrt(n.doubleValue());
  int root = toCount.intValue();
  for(int i = 3 ; i <= root ; i = i + 2) {
    if(n % i == 0 ) return false;
  return true;


Edited by some0ne

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.