November 22nd, 2004, 10:41 PM

help!!!
ive never done any programing before, im not even taking a class on programing but i need to learn python to be able to make models for my environmental modeling class. i have a homework assignment relating to what i need to learn but have no idea what im doing. can anyone help me with a program that will print all the numbers from 1 to 100 and their prime factors?
November 22nd, 2004, 10:48 PM

Code:
for n in range(1, 101):
print n
is the first part, for the second one you need to show some of your own work first...
November 22nd, 2004, 11:02 PM

i think my first step would be to determine if 2 is one of the numbers factors, since its the first prime number greater than 1.
so i have :
a in range (1,101)
print a
b=a/2
if b>1:
>>print b
if b%1==0
print b
print a,2
am i getting anywhere with this?
November 22nd, 2004, 11:05 PM

can you tell i have no idea what im doing
November 23rd, 2004, 01:11 AM

Hi,
I can provide the flowchart...but you wld have to try the program yourself...as its your assignment Ppl here will readily help you out if you encounter problems
<prime factors for number > 1>

<myFactor=call a function returnFactor(n)>

<n=n div myFactor>

<repeat the above 2 steps till u get 1, to print out all the factors>
<function returnFactor(n)>

<chk if number is even>YES<factor=2>
NO
<factor=0, buffer=3>

<while factor==0>

<if buffer>sqrt(n)><factor=n>

<elif n mod buffer == 0><factor=buffer>

<else buffer=buffer+2>

<finally return factor>
Rgds,
Subha
November 23rd, 2004, 02:57 AM

Guess you will be able to do the coding...if not then I cld provide the program...mine works!
Rgds,
Subha