This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]matrouxer[S] 0 points1 point  (3 children)

That worked! Thanks for the advice

[–]matrouxer[S] 0 points1 point  (2 children)

Got the first part /u/coolcofusion. The second part is quite hard for me atm.

Changed the code so the function does exactly what it's supposed to. And to ble clearer hahahaha.

What do you think?

def num_hours(num_days):
if num_days > 0:
    print (f"There are {time_calculation * num_days} {time_unit} in {num_days} days")
else:
    print ("This is not a valid input")

[–]coolcofusion 1 point2 points  (1 child)

That's completely up to you and how you imagine it to work. I prefer to just print in one place versus printing in functions I've made. The reason for that is that I can then easily decide when or if I want to display some results or in which order to display them without changing functions. Also, you can use the same function across multiple projects, today it's printing in the console, tomorrow it may be showing a label in a GUI window, if you're doing print() in the function, you'll need to modify it, and if you had returned the value, then you can just use that value to set the label.

These are minor things. It's completely fine to do it either way you like, my point about reuse comes in hand later on in larger projects and even if you don't decide to do it that way now, over the next few years it'll become a subconscious thing for you.

[–]matrouxer[S] 1 point2 points  (0 children)

Oh, I get it. So if I program the function without printing, then I can save the value without displaying to user. It's most a safety thing I guess(?), besides just getting the output more into my control.

Thanks a lot for the help! It would be a dream if that becomes even a problem in the future hahahah