Click here to Skip to main content
15,938,848 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 3-Jan-23 11:30am

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.
Share this answer
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[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

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