# Untitled

unknown
python
6 months ago
2.4 kB
3
Indexable
Never
```# User-friendly prime factor calculator

number = 0

while number <= 0:
try:
original = input("Enter a positive integer: ")
number = int(original)
if number > 0:
break #breaks out of the prompt to input a positive integer, once user successfully enters positive integer
print("Incorrect input, please enter positive integer")
except ValueError:
print("Incorrect input, please enter positive integer")

print("The prime factors are: ")
for fac in range(2, int(number + 1)):
if number % fac == 0:
prime = True
for i in range(2, fac):
if fac % i == 0:
prime = False
break
if prime:
print(fac)

####
# User-friendly smart prime factor calculator

number = 0

while number <= 0:
try:
original = input("Enter a positive integer: ")
number = int(original)
if number > 0:
break #breaks out of the prompt to input a positive integer, once user successfully enters positive integer
print("The input is negative/zero, enter a positive integer")
except ValueError:
extracted = ""
for ch in original:
if ch.isdigit():
extracted = extracted + ch
if len(extracted) == 0:
print("Input consists of no digits, please enter positive integer")
else:
print("Warning: The input was cleaned to extract the digits. The input was", original + ",", "and the extracted integer was", extracted)
number = int(extracted)
if number > 0:
break #breaks out of the prompt to input a positive integer, once user successfully enters positive integer
print("The input is negative/zero, enter a positive integer")

print("The prime factors are: ")
for fac in range(2, int(number + 1)):
if number % fac == 0:
prime = True
for i in range(2, fac):
if fac % i == 0:
prime = False
break
if prime:
print(fac)

####
# Number of words in a sentence

end = "end program"

while True:
sentence = input("Enter a sentence written in English: ")
if sentence == end:
break
space_count = 0
for ch in sentence:
if ch == " ":
space_count = space_count + 1
print("Word count:", space_count + 1)

```