r/learnpython •

Printing local variables outside of a function

[deleted] — view deleted post

0 Upvotes

14 comments sorted by

View all comments

Show parent comment

4

u/socal_nerdtastic Oct 05 '26

You could return the segment (aka string) to be printed.

def total_seconds(hours1, minutes1, seconds1):
  total = (hours1*60*60)+(minutes1*60)+seconds1
  return f'{hours1} hours, {minutes1} minutes and {seconds1} seconds have a total of {total} seconds.')

print(total_seconds(7,21,37))

Edit: fixed your typo that didn't display minutes.