Skip to content
Advertisement

How to understand the error in my Python program

code for printing factors of a number

I’m trying to code a program that prints the factors of a number, just as shown in the attached image, but the outcome is totally not what I’m expecting. (I just want the code to return factors of the specified number.) What am I doing wrong and what is the correct way of doing it?

Code:

JavaScript

Output:

JavaScript

Advertisement

Answer

As to why your program does not work, let’s see what is going on step by step:

JavaScript

See the problem in logic now?

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement