Python newbie weird output #21448
-
The code I posted below works accordingly to my expectations except for 1 problem. When it goes into the factorial route, after the number is determined as a prime number, ill see for example: 2! = 2none. The “none” here is the problem, but I have no idea where and what is causing that “none” to appear here. If there’s any suggestions or solutions, I would really appreciate it!
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hikari334:
This line is the reason: It writes the return value of the There are a number of other issues with the
|
Beta Was this translation helpful? Give feedback.
-
Ah thanks man, got it fixed up! |
Beta Was this translation helpful? Give feedback.
This line is the reason: It writes the return value of the
factorial()
function to standard output. There is no explicitreturn
statement in the function, so the return value isNone
.There are a number of other issues with the
factorial()
function:It uses the global variable
number
instead of a parameter.Don’t use the
end
parameter toprint()
for data. Instead better return the calculated value and format the result.If the parameter
number
is invalid, the function should raise an error instead of just writing a message.