0

I have a code like this, but I dont know where is the mistake

x = int(input())

hh = x // 3600
second = x % 3600
mm = second // 60
ss = second % 60

print("%d remaining seconds is equal to %d:%d:%d".format(x, hh, second, mm, ss))

#Output
%d remaining seconds in equal to %d:%d:%d < I dont know why this code still %d and didnt change into numbers

And when I use print("%d remaining seconds is equal to %d:%d:%d" % (x, hh, second, mm, ss)) there will be the error not all arguments converted during string formatting

Any suggestion ?

Mr. T
  • 11,960
  • 10
  • 32
  • 54
Tito Yudha
  • 39
  • 6
  • See also this for the current approach to string formatting: https://realpython.com/python-f-strings/ – Mr. T Mar 06 '21 at 10:12

2 Answers2

3

Instead of format why not use an f-string, that will allow you to embed the variables directly in the string.

print(f"{x} remaining seconds is equal to {hh}:{second}:{mm}:{ss}")
norie
  • 9,609
  • 2
  • 11
  • 18
1

you need to change print line to this line

print("{} remaining seconds is equal to {}:{}:{}:{}".format(x, hh, second, mm, ss))

or

print("%d remaining seconds is equal to %d:%d:%d:%d" % (x, hh, second, mm, ss))
Vatsal Parsaniya
  • 899
  • 6
  • 15