-3

my code:

import time
import datetime
from typing import Any


def countdown(h, m, s):
    total_seconds: int | Any = h * 3600 + m * 60 + s
    minim: int | Any = 0
    while int(total_seconds) > int(minim):
        timer = datetime.timedelta(seconds=int(total_seconds))
        print(timer, end="\r")
        time.sleep(1)
        total_seconds -= 1
    print("Bzzzt! The countdown is at zero seconds!")


h = input("Time in hour :")
m = input("Time in minute :")
s = input("Time in seconds :")
countdown(h, m, s)

When I execute my code in the window Terminal it works fine, but when I put it in a window it give me this error :

Traceback (most recent call last):
  File "File", line 1491, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "File", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "File>
    countdown(h, m, s)
  File "File", line 10, in countdown
    timer = datetime.timedelta(seconds=int(total_seconds))
OverflowError: Python int too large to convert to C int
Ariel Gluzman
  • 166
  • 1
  • 6
  • 1
    What does "putting it in a window" mean? – deceze Oct 13 '22 at 09:52
  • Hint: where the code says `total_seconds: int | Any = h * 3600 + m * 60 + s`, what does this tell you about the **intended** type of `total_seconds`? Therefore, *should it be necessary* to do `int(total_seconds)` later? But you did this, presumably because there was a different bug before. What was wrong then? Next hint: **should** `h`, `m`, and `s` be integers, or strings? Why? What **are** they? Therefore, what needs to be changed? – Karl Knechtel Oct 14 '22 at 03:53

1 Answers1

2

You forgot to cast to int, and the ints and strings got mixed up afterwards, change:

total_seconds: int | Any = h * 3600 + m * 60 + s

to:

total_seconds: int | Any = int(h) * 3600 + int(m) * 60 + int(s)

hope i helped.

Ariel Gluzman
  • 166
  • 1
  • 6