-1

I'm making a timer and I got it to tick down, and display properly in the command prompt with this:

min = (code for counting minutes)
sec = (code for counting seconds)

print( min , ":" , sec , sep="" )
12:34

Now I want to make what is printed in to a variable/string so I could use it in other code. Btw I don't need for the time to display the time in cmd, I just need to make min:sec in to a variable.

martineau
  • 119,623
  • 25
  • 170
  • 301
  • Does this answer your question? [How can I concatenate str and int objects?](https://stackoverflow.com/questions/25675943/how-can-i-concatenate-str-and-int-objects) – Tomerikoo Nov 11 '20 at 08:23
  • Are you using classes? if you aren't then place the `min` and `sec` outside of your `definitions` – Bob Nov 11 '20 at 09:09

1 Answers1

1

I believe, you'll also want to format the time with leading zeros, i.e. 03:04 instead of 3:4. The simplest way is using the f-strings:

v = f'{min:02}:{sec:02}'

For pre-3.6, you can use str.format() instead:

v = '{:02}:{02}'.format(min, sec)
bereal
  • 32,519
  • 6
  • 58
  • 104