Py.Cafe

Streamlit Examples on Py.cafe

DocsPricing
  • AzTimer.py
  • WeatherCondition.py
  • app.py
  • requirements.txt
AzTimer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import time
import sys

def format_time(total_seconds):
    hours = total_seconds // 3600
    minutes = (total_seconds % 3600) // 60
    seconds = total_seconds % 60
    return f"{hours:02d}:{minutes:02d}:{seconds:02d}"

def phone_style_timer():
    total_seconds_input = 0
    while True:
        try:
            print("Set the time for the timer:")
            hours_str = input("Hours (0-23): ")
            minutes_str = input("Minutes (0-59): ")
            seconds_str = input("Seconds (0-59): ")

            hours = int(hours_str)
            minutes = int(minutes_str)
            seconds = int(seconds_str)

            if not (0 <= hours <= 23 and
                    0 <= minutes <= 59 and
                    0 <= seconds <= 59):
                print("Error: Please enter valid values ​​(hours 0-23, minutes/seconds 0-59).")
                continue

            total_seconds_input = hours * 3600 + minutes * 60 + seconds
            if total_seconds_input <= 0:
                print("Error: Total time must be greater than zero.")
                continue
            break
        except ValueError:
            print("Ошибка: Введите только целые числа.")

    print("\nТаймер запущен!")

    while total_seconds_input >= 0:
        sys.stdout.write(f"\rОсталось: {format_time(total_seconds_input)}")
        sys.stdout.flush()
        time.sleep(1)
        total_seconds_input -= 1

    print("\nВремя вышло!")
phone_style_timer()