Reputation: 11
Hi im a beginner python user. I coded a thing just for practice but im getting ''none'' instead of the result. code is like this : code
i think im using str function wrong but i dont know how to fix it. thanks for your help
Upvotes: 1
Views: 83
Reputation: 68
you should use return
instead of print
def work_time(mathematic, chemistry, biology):
return mathematic*2 + chemistry*1 + biology*(0.5)
print("I will study " + str(work_time(1, 2,3) ) + " hours today")
Upvotes: 0
Reputation: 26
none is telling you that the function is not returning a value so you must use the return keyword
Upvotes: 0
Reputation:
See, when you don't use the return
keyword, a function returns None
. So when you print a function which returns None
, Then None
will be printing.
So, use the return
keyword.
def work_time(mathematic, chemistry, biology):
print(mathematic*2 + chemistry*1 + biology*(0.5))
return mathematic*2 + chemistry*1 + biology*(0.5)
print("I will study " + str(work_time(1, 2,3) ) + " hours today")
Upvotes: 2
Reputation:
I can't see an image or code but things that can result to none can be:- 1.Not returning a blue from function 2.Keeping a boolean inactive 3.Not defining codes
Upvotes: 0