..
Applying Knowledge - Class 6 (part 1)
Create a Python program that reads an integer and ensures it is a positive number, then calculates and displays its divisors.
The input value must be validated because this program only accepts positive numbers. If the input value is out of range, the program will display the message INVALID VALUE and will prompt for input again until a valid number is provided.
The output will list the divisors of the input number, each on a new line, following the examples provided.
Input:
- One positive integer.
Output:
- The divisors of this number, listed one below the other.
Sample Inputs/Outputs:
foo@bar:~$ py baz.py
-5
INVALID VALUE
0
INVALID VALUE
12
1
2
3
4
6
12
foo@bar:~$
foo@bar:~$ py baz.py
5
1
5
foo@bar:~$
SOLUTION:
while True:
x = int(input())
if x < 1:
print('VALOR INVÁLIDO')
else:
for y in range(1, x+1):
if x%y == 0:
print(y)
break