![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| python 2.4 on SCO 5.0.6 | ananth_ak | SCO | 0 | 02-21-2008 03:01 AM |
| Foresight: python | iBot | Security Advisories (RSS) | 0 | 02-12-2008 09:30 AM |
| what is python? | kprescod4158 | Shell Programming and Scripting | 1 | 11-20-2007 04:58 PM |
| Python 2.5 must die. | Dbecker | UNIX for Dummies Questions & Answers | 2 | 01-30-2007 08:35 AM |
| Python Help | MAdSAcRAfICe | UNIX for Dummies Questions & Answers | 1 | 08-12-2002 12:20 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
I have written a small practice Python script to determine the prime numbers between 2-10, for practice. Although I have pored over this script numurous times, I have not found the problem.
The problem is: Python will not print "is a prime" when a number is a prime. After examining the code below, this will make sense.. Code:
for i in range(2,10): print print i,"-", for j in range(2,i): if (i % j) == 0: print j, else: if j == i + 1: print "is a Prime" Code:
2 - 3 - 4 - 2 5 - 6 - 2 3 7 - 8 - 2 4 9 - 3 I believe line 8 may be a problem. I am not sure whether to use "j - 1 == i" or j == i + 1". Thank you, Furtoes00 Last edited by Furtoes00; 04-13-2002 at 03:38 AM. |
| Forum Sponsor | ||
|
|
|
|||
|
First - I have no idea what Python is.
Second - that means I have no idea of it's syntax. BUT - As Spock would say "Logic suggest..." This code you posted: if (i % j) == 0: print j, else: if j == i + 1: print "is a Prime" IF it prints j, you will never go to the else. Logic is logic - if (true) then do this ELSE do this - you need to change this so it looks at each separately or looks at the second within the if if (true) then print j if (true) then print "is a Prime" |