15,615,466 members
See more:
Complete the code to find if a given number is a prime number? The program will take a positive integer greater than 1 as input and indicate if it is a prime number by saying "prime", and if it is not a prime number saying "not a prime". Note there are 3 places in the given code that you need to fix for this code to work properly and give the expected output.

i = int(input())
j = 5 # fix the code (1)
while (j <= (i/j)):
if not(i%j):
print("not a prime")
continue # fix the code (2)
j = j + 2 # fix the code (3)
if (j > i/j):
print ("prime")

What I have tried:

I can't Understand because I am new to programing
Posted
Updated 3-Jan-23 11:30am

## Solution 1

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

## Solution 2

Quote:
How to fix that 3 codes

In this kind of problem, either the program contain syntax errors, either the program don't do what it is supposed to do.
The best option is to run the program and see what happens.
If syntax error, search in documentation what is wrong.
If program runs, check that you get correct result or not, for wrong results rebuild the logic and see what is not as expected.

Top Experts
Last 24hrsThis month
 OriginalGriff 195 Richard MacCutchan 115 raddevus 75 Dave Kreskowiak 38 Rick York 30
 OriginalGriff 3,116 Richard MacCutchan 1,381 Graeme_Grant 965 Dave Kreskowiak 689 CHill60 385

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900