Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions dahnovskauo/second/task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'''
Користувач вводить час у форматі `hh:mm(:ss(.ms))`, де дужки позначають необов'язковість.
Напишіть функцію, що повертає кількість повних секунд, що пройшли з опівночі.
Виведіть результат.
У випадку помилкового вводу виведіть повідомлення про помилку.
'''

import re
re_form = re.compile(r'/d/d')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this: /d/d to this: \d\d

def validator(pattern, promt):
text = input(promt)
while not bool(pattern.match(text)):
text = input(promt)
return text

hours = int(validator(re_form ,'Введіть години hh:'))
min = int(validator(re_form ,'Введіть хвилини mm:'))
sec = int(validator(re_form ,'Введіть секунди(необ.) ss:'))
msec = int(validator(re_form ,'Введіть мілісекунди(необ.) ms: '))

time = hours*3600 + min*60 + sec + msec*0.001
print(time)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name programs output: print("Результат: " + time)`