The Lounge This is the General Talk forum.

Anybody know how to use program with Python?

Thread Tools
 
Search this Thread
 
  #1  
Old 10-12-2009 | 05:09 PM
PistonsFan102's Avatar
Thread Starter
|
Senior Member
Joined: Mar 2006
Posts: 1,183
Default 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.
 
  #2  
Old 10-12-2009 | 05:21 PM
01FR500's Avatar
I'd Hit It
Joined: Sep 2006
Posts: 2,847
From: Texarkana, TX/Conway, AR
Default

UH, WTF? This must be some specialized stuff because my required general education isn't recognizing. I've had an accounting class though.
 
  #3  
Old 10-12-2009 | 05:28 PM
PistonsFan102's Avatar
Thread Starter
|
Senior Member
Joined: Mar 2006
Posts: 1,183
Default

I'm an Accounting and "information systems" major. So thats why I have to do this
 
  #4  
Old 10-13-2009 | 10:26 AM
r3dn3ck's Avatar
Wowbagger hates me too!
Joined: Nov 2005
Posts: 9,865
From: Magrathea/California
Default

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'
 

Last edited by r3dn3ck; 10-13-2009 at 10:37 AM.
  #5  
Old 10-14-2009 | 06:44 AM
TUFF 4.6's Avatar
"Just Add Foot"
Joined: Dec 2007
Posts: 2,250
From: Richmond Va.
Default

Does this go back to the "Chinese Arithmetic" thing ?
 
  #6  
Old 10-14-2009 | 08:26 AM
WNRacing's Avatar
KWITCHERBITCHIN
Joined: Sep 2007
Posts: 6,024
From: Gallatin, TN
Default

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!
 
  #7  
Old 10-14-2009 | 11:19 AM
r3dn3ck's Avatar
Wowbagger hates me too!
Joined: Nov 2005
Posts: 9,865
From: Magrathea/California
Default

the letters are numbers. Ever heard of pi? It's not filled with fruit.
 
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
eventer289
General Tech Forum
16
11-29-2006 08:00 PM
dannyb785
The Lounge
2
04-05-2006 06:36 PM
dannyb785
Pictures
15
11-06-2005 01:11 PM
babyjo
Modular 4.6L Tech
8
03-20-2005 09:48 AM
DIESEL
The Lounge
4
12-19-2004 08:19 PM




All times are GMT -7. The time now is 03:43 AM.