Practice problem doubt: What time is it?

Hi, my concern here is how i can print the time like i expected to happen. I tried everything and i know the syntax is wrong but can anyone show me the right way to print time?Maybe in one line? I am not able to figure it out.

Screen Link:

My Code:

hour = seconds // 3600 
minute = (seconds - hour * 3600) // 60
t_1 = "The current time is"
t_2 = (hour:minute)
t_3 = t_1 + ' ' + t_2 

What I expected to happen:
“The current time is 13:30.”

What actually happened:

File "<ipython-input-1-16b4e7b8131a>", line 7
    t_2 = (hour:minute)
SyntaxError: invalid syntax

You can use .format or f-string.

print('The correct time is {}:{}'.format(hour, minute))
1 Like

@monorienaghogho thank you, it worked. I haven’t come across this syntax till now. Can you explain it or tell me that in when i will face it? I am currently on step 1 mission 6.

1 Like

You will use all the formats on the course.

Keep going!!

1 Like

Hello @uditchauhan, Another way would be

This is not valid python syntax.

It supposed to be

t_2 = str(hour) + ':' + str(minute)

Using + we can concatenate two strings. But here minute and hour is numeric type so we will have to convert it to string type first to concatenate. We can convert numeric to string type using in-built str function.


thanks @DishinGoyani. I tried this at first before you suggested but I might have done something wrong. But this thought surely crossed my mind. Thank you for the right syntax.

1 Like

seconds = 48600
hour = seconds // 3600
minute = (seconds - hour * 3600) // 60
print(f" The current time is {hour} : {minute}")

where does the number 3600 come from ?

1 Like

Hi @theskyzlimit,

Welcome to the Community! :tada:
3600 is the number of seconds in an hour.