-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexe_024_units_time.py
60 lines (45 loc) · 1.65 KB
/
exe_024_units_time.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
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
Create a program that reads a duration from the user as a
number of DAYS, HOURS, MINUTES, and SECONDS.
Compute and display the total number of SECONDS represented by this duration.
"""
# START Definition of FUNCTION
def valutaIntPositive(numero):
if numero.isdigit():
if numero != "0":
return True
return False
# END Definition of FUNCTION
# Acquisition and Control of the DATA entered by the USER
print("Enter the Duration (days, hours, minutes and seconds).")
days = input("Days: ")
hours = input("Hours: ")
minutes = input("Minutes: ")
seconds = input("Seconds: ")
daysIntPositive = valutaIntPositive(days)
hoursIntPositive = valutaIntPositive(hours)
minutesIntPositive = valutaIntPositive(minutes)
secondsIntPositive = valutaIntPositive(seconds)
while not(daysIntPositive and hoursIntPositive and minutesIntPositive and secondsIntPositive):
print("Incorrect entry. Try again.")
print("Enter the Duration (days, hours, minutes and seconds).")
days = input("Days: ")
hours = input("Hours: ")
minutes = input("Minutes: ")
seconds = input("Seconds: ")
daysIntPositive = valutaIntPositive(days)
hoursIntPositive = valutaIntPositive(hours)
minutesIntPositive = valutaIntPositive(minutes)
secondsIntPositive = valutaIntPositive(seconds)
# Conversion STR -> INT
days = int(days)
hours = int(hours)
minutes = int(minutes)
seconds = int(seconds)
# TIME Computing (seconds)
secondsMinutes = minutes * 60
secondsHours = hours * (60 * 60)
secondsDays = days * (60 * 60 * 24)
duration = seconds + secondsMinutes + secondsHours + secondsDays
# Displaying the RESULT
print(f'DURATION entered = {duration} seconds')