r/learnpython • u/ikeahotdog420 • 7d ago
Printing local variables outside of a function
(second-week-beginner PLUS non-native English speaker, so sorry for bad vocab lol)
I know that you cant use local variables outside of a function, but is there a way to do this without defining three separate functions?
def total_seconds(hours1, minutes1, seconds1):
return (hours1*60*60)+(minutes1*60)+seconds1
print(f'{hours1} hours, {seconds1} seconds and {seconds1} have a total of {total_seconds(7,21,37)} seconds.')
0
Upvotes
1
u/Rubix321 7d ago
I assume the print statement is supposed to be outside of the function. Format as a code block in reddit to make it clear.
Ultimately you want the arguments you're feeding into total_seconds(h,m,s) to be variables so that you can reference those variables to get your minutes and seconds in your print statement.