Anybody know how to use program with Python?
#1
Anybody know how to use program with Python?
I have this retarded problem.
The following code prints all the divisors of input integer n. By adding some lines of code change the program to also print whether or not n is prim. Print the output for each input: 8,31, 56, 57.
def divisor(n):
for i in range(1,n+1,1):
if n%i == 0:
print i
I am an accounting major I don't need to know how to program.
I thought it was worth a shot to post it on here lol.
The following code prints all the divisors of input integer n. By adding some lines of code change the program to also print whether or not n is prim. Print the output for each input: 8,31, 56, 57.
def divisor(n):
for i in range(1,n+1,1):
if n%i == 0:
print i
I am an accounting major I don't need to know how to program.
I thought it was worth a shot to post it on here lol.
#4
looking at your code.
Just my best guess... haven't touched python in a LONG time.
for n in [8, 31, 56, 57]:
for x in range(2, n):
if n % x == 0:
break
else:
# loop finished wtihout finding a factor
print n, 'is a prime number'
Just my best guess... haven't touched python in a LONG time.
for n in [8, 31, 56, 57]:
for x in range(2, n):
if n % x == 0:
break
else:
# loop finished wtihout finding a factor
print n, 'is a prime number'
Last edited by r3dn3ck; 10-13-2009 at 09:37 AM.
#6
Dude, I have no idea what is going on in here.... Letters and numbers trying to solve some kind of an equation thing.. I'm sorry, letters do not belong in matematical equations. Math = numbers.
Bah!
Bah!
Thread
Thread Starter
Forum
Replies
Last Post