You need to create a program that outputs the number of approximate numbers and prime numbers of integers from 2 to n by receiving more than 2 integers, but it gets blocked at the output part.
def readNumber():
while True:
n = int (input ("Enter an integer")
if (n >= 2):
break
else:
print("Please enter a number greater than or equal to 2.")
continue
def getCountsOfDivisors(n):
count = 0
for i in range(1, n+1):
if n % i == 0:
count += 1
print(count)
def isPrime(n):
for f in range(2, n-1):
if n % f == 0:
print("False")
else:
print("True")
num = readNumber()
for t in range (2, num + 1):
print("integer:" + str(t) +"minimal number:" + str(getCountsOfDivisors(t)) +"minority:" + str(isPrime(t))))
I made the code like this.
Traceback (most recent call last):
File "C:\Users\Desktop\Desktop\202110943 Ahn Se-ho Practice Assignment #07.py", line 28, in <module>
for t in range (2, num + 1):
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
There's an error like this. What's the problem?
This is because there is no return value (return value) for the readNumber function.
Please add the return value as below.
def readNumber():
while True:
n = int (input ("Enter an integer")
if (n >= 2):
break
else:
print("Please enter a number greater than or equal to 2.")
continue
return n
First of all, the reason for the error is as above.
But I think other functions should have a return value.
I think you should find the part in the textbook that deals with the return value of the function and read it.
© 2024 OneMinuteCode. All rights reserved.