-
Notifications
You must be signed in to change notification settings - Fork 0
/
4_divisors.py
27 lines (22 loc) · 907 Bytes
/
4_divisors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
###############################################################################
# Exercise 4: Divisors (PracticePython)
# Author: Jenny Hamer
#
# Description: Ask the user for a number; then, print out all divisors of that
# number.
###############################################################################
while True:
try:
user_num = int(input("Please enter a number: "))
break
except ValueError:
print("Oh no, that's not a valid number! Please try again...")
print_style = input("Please enter 'yes' to see the numbers one by one, 'no' to see them in a list: ")
possible_divisors = range(2, user_num)
divisors = [x for x in possible_divisors if user_num % x == 0]
print("Here is a list of numbers which divide", user_num)
if print_style.lower() == "no":
print(divisors)
else:
for i in range(len(divisors)):
print(divisors[i])