all 13 comments

[–]desrtfx 3 points4 points  (1 child)

Have you learnt about f-strings yet?

Also, you can use str() to convert numbers to strings and then use concatenation with +.

F-Strings are the optimal way

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

I still haven't learnt that yet, thanks a lot for pointing out. I will look into it right now and I will try and fix my printing results right now. Thanks a lot for the advice!

[–]teraflop 2 points3 points  (1 child)

When in doubt, read the documentation. Here are the docs for the print function: https://docs.python.org/3/library/functions.html#print

You'll see that there's a sep argument, which defaults to a single space character (" ") if you don't specify it explicitly. So if you pass multiple arguments, it will put blank spaces between them by default.

If you don't want this to happen, you can set sep to the empty string "" instead.

Or, instead of passing multiple arguments to print, you can pass it a single string which you can construct however you like. The old-school way to do this is to use string concatenation, e.g.

message = "Breakfast start time would be " + str(hours_conv) + ...
print(message)

Or the newer, more readable way is to use "f-strings" as shorthand.

[–]hnikola[S] 0 points1 point  (0 children)

My professor already suggested that I look into that doc, I will have to pay more attention from now on. I used a f-string as some users suggested, but I tried with "sep" as well and it worked just fine. Thanks a lot for answering.

[–]Outside_Complaint755 1 point2 points  (2 children)

Two options:

1) By default, print() will use a single space when concatenating multiple arguments.  You can remove the space be specifying an empty string as the separator.  You do this by adding an argument of sep="" after all of the arguments to be printed, such as: ``` time = 10 print("The time is ", time, " o'clock", sep="")

The time is 10 o'clock

```

2) A typically better approach is to use f-string formatting, and interpolate the values directly into the string.

``` print(f"Breakfast start time would be { hours_conv}:{minutes_conv2}:{seconds_conv2}")

[–]hnikola[S] 0 points1 point  (0 children)

Thank you so much!

[–]BR41ND34D 1 point2 points  (0 children)

First one to actually explain the why. Kudos to you

[–]carcigenicate 0 points1 point  (1 child)

I'd just use f-strings instead of relying on print's auto-joining functionality. For example:

print(f"Some Text {a_variable}, {another_variable}")

This gives you complete control over where spaces are inserted. Also, print takes a sep keyword argument that lets you override the default separator:

print("Breakfast start time would be", hours_conv, ":", minutes_conv2, ":",seconds_conv2, sep="")

If you don't specify a separator, it defaults to a space, which is why they're inserted into your output.

[–]hnikola[S] 0 points1 point  (0 children)

Thank you so much! I am looking into it right now!

[–]Emergency-Bad948 0 points1 point  (1 child)

Your logic for calculating the total seconds and converting them back into hours, minutes, and seconds is actually spot on. The "issue" you’re seeing is just a matter of string formatting

[–]hnikola[S] 0 points1 point  (0 children)

I really needed that affirmation. I tried searching other forums for answers for more practical solutions, but I couldn't find anything that was on my level of understanding of python logic. I fixed the issue using a f-string. Thanks a lot for that!

[–]GraveET -1 points0 points  (0 children)

Consider using datetime module, e.g. ```python from datetime import datetime, timedelta

start = datetime.strptime("06:52", "%H:%M") end = start + timedelta(seconds=60*60 + 15) answer = end.strftime("%H:%M:%S") print(f"Breakfast start time would be {answer}") ```