Python - Check if numbers in list are factors of a number
Posted
by Zach
on Stack Overflow
See other posts from Stack Overflow
or by Zach
Published on 2010-03-14T17:09:58Z
Indexed on
2010/03/14
17:15 UTC
Read the original article
Hit count: 527
Hey,
I have a list
of numbers (integers
) (say, from 1 to 10).
They're not necessarily consecutive, but they are in ascending order.
I've prompted the user multiple times to enter a choice of the available numbers. When that number is entered, it is removed from the list along with any of its factors that may be there.
I've prevented the user from selecting prime numbers. However, at some point in time, there may be non-prime numbers there, which have no factors remaining.
I'm relatively new to Python, so I'm having trouble implementing:
Checking if the number selected has no factors remaining (even if it is not prime).
Checking if only prime numbers remain, or numbers without factors.
I'm thinking of using for
statements, but I'm not sure exactly how to implement them. Can anyone offer advice, or code? Thanks in advance...
PS. In case anyone's wondering, I'm doing an implementation of the game of Taxman in Python.
© Stack Overflow or respective owner