## What is the fault of this program?

A forum for general discussion of the Python programming language.

### What is the fault of this program?

I created this program to display prime numbers between 1 to 10. But there have fault. Please help me.

Code: Select all
`A = 2while (A <= 10) :    Isprime = 1    B =2    while (B < A) :        if (A % B == 0) :            Isprime = 0            B = B+1        else : B = B+1    else :        if (Isprime != 0) :            print(A)        else : A = A+1`
Last edited by stranac on Thu Oct 24, 2013 12:48 pm, edited 1 time in total.
Reason: First post lock.
My Python Version is 3.2.3
b849961@drdrb.com

Posts: 13
Joined: Thu Oct 24, 2013 12:41 pm

### Re: What is the fault of this program?

What's the problem?
If you're getting an error traceback, paste it, if not explain what's not working as you wanted.
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

### Re: What is the fault of this program?

stranac wrote:

What's the problem?
If you're getting an error traceback, paste it, if not explain what's not working as you wanted.

Untitled.jpg (72.23 KiB) Viewed 1089 times
My Python Version is 3.2.3
b849961@drdrb.com

Posts: 13
Joined: Thu Oct 24, 2013 12:41 pm

### Re: What is the fault of this program?

Hi b849961@drdrb.com, welcome to the forums! Your code basically comes down to this:

Code: Select all
`A = 2while (A <= 10) : # A will never be increased -> endless loop    Isprime = 1    B =2    while (B < A) : # never true, skip this block        pass    else :        if (Isprime != 0) : # always true            print(A) # Here the number 2 is printed        else : A = A+1 # this will never be reached# and then it begins again. 2, 2, 2, 2, 2, etc.`

I am not sure what you intended to do, and what went wrong, but this explains why it is happening like that.
Due to the reasons discussed here we are moving to python-forum.net on October 1, 2016.

This forum will be closed. Please create an account at the new site to continue discussion.

IRC://irc.freenode.net/python-forum
Kebap

Posts: 689
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

### Re: What is the fault of this program?

Kebap wrote:Hi b849961@drdrb.com, welcome to the forums! Your code basically comes down to this:

Code: Select all
`A = 2while (A <= 10) : # A will never be increased -> endless loop    Isprime = 1    B =2    while (B < A) : # never true, skip this block        pass    else :        if (Isprime != 0) : # always true            print(A) # Here the number 2 is printed        else : A = A+1 # this will never be reached# and then it begins again. 2, 2, 2, 2, 2, etc.`

I am not sure what you intended to do, and what went wrong, but this explains why it is happening like that.

Thank you Kebap. Your explaining is succeed my program. Thank you. If you want code here that code.

Code: Select all
`A = 2while (A <= 10) :    Isprime = 1    B =2    while (B < A) :        if (A % B == 0) :            Isprime = 0            B = B+1        else : B = B+1    else :        if (Isprime != 0) :            print(A)            A = A+1        else : A = A+1`
My Python Version is 3.2.3
b849961@drdrb.com

Posts: 13
Joined: Thu Oct 24, 2013 12:41 pm