### Thread: I need help with my assignment

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2013
Posts
2
Rep Power
0

#### I need help with my assignment

Write a program that counts a number's factors and determines whether
the number is prime.

What is your favorite number? 24
24 has 8 factors
24 is not prime

What is your favorite number? 31
31 has 2 factors
31 is prime

Hint: To count the factors of some integer n, use a loop that tests
every integer less than n to see whether n is divisible by it. (How
do you know whether one integer is divisible by another?)

i= ""
number = 0
count= 0

def factor_count():
i, count = 1, 0
number = int(raw_input("What is your favorite number?"))
while(i <= number):
if number % i == 0:
count +=1
i += 1
print(number, "has", count, "factors")
if (count == 2):
print(number, "is prime")
else:
print(number, "is not prime")
Last edited by K Monekwe; November 2nd, 2013 at 05:55 AM. Reason: my code
2. Write a program
You see, assignment tells you to write a program. So start writing it and when you encounter some specific trouble - feel free to post the specific question here... Along with _your_ code.
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2013
Posts
2
Rep Power
0
this is what i managed to come up with, but when i run it it does not give me what the question asks

number = 0

def factor_count():
i, count = 1, 0
number = int(raw_input("What is your favorite number?"))

while(i <= number):
if number % i == 0:
count +=1
i += 1
print(number, "has", count, "factors")
if (count == 2):
print(number, "is prime")
else:
print(number, "is not prime")
4. Could you edit your post and put [ code ] and [/ code ] tags around it?

You know it is extremely important for python to preserve indentation and in your post indentation is completely lost because of formatting.

By the way it looks you have function "factor_count" but you never call it at all. Of course if you never call it, it will never ask be executed and never ask you to input anything.

UPD: I see, this is not your code at all. It is from yahoo answers: