Here is the problem. I find the wording they used to be a bit confusing:
- Write a program that displays all the numbers, greater than one, that divide a number, obtained from the user, evenly (no remainder after division). If the number does not have any even divisors (it is prime), then print "None" instead. Do not include the number itself.
Here is my solution:
Also, just a quick disclaimer I am a beginner programmer so please don't suggest anything too overly complicated that I likely wouldn't have learned yet : ) I appreciate it!
def check_divisors(user_num):
"""
This function checks if the user entered an
even number and displays the numbers if even.
Parameter: Int - user_num entered by user
Return Value: None (only printing)
"""
for i in range(2, user_num):
if user_num % i == 0:
print(user_num)
else:
print("None")
def main():
try:
user_num = int(input("Enter a number: "))
except ValueError:
print("Invalid input")
check_divisors(user_num)
if __name__ == "__main__":
main()