-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy-python-project.py
More file actions
33 lines (33 loc) · 1.42 KB
/
my-python-project.py
File metadata and controls
33 lines (33 loc) · 1.42 KB
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
def days_to_units(num_of_days, conversion_unit):
if conversion_unit == "h":
return f"{num_of_days} days are {num_of_days * 24} hours"
elif conversion_unit == "m":
return f"{num_of_days} days are {num_of_days * 24 * 60} minutes"
elif conversion_unit == "s":
return f"{num_of_days} days are {num_of_days * 24 *60 *60} seconds"
else:
return "unsupported unit"
def validate_and_execute(days_and_unit_dictionary):
try:
user_input_number = int(days_and_unit_dictionary["days"])
# conversie doar pentru numere pozitive
if user_input_number > 0:
calculated_value = days_to_units(user_input_number, days_and_unit_dictionary["unit"])
print(calculated_value)
elif user_input_number == 0:
print("you entered a 0, please enter a valid positive number")
else:
print("you entered a negative number, no conversion for you!")
except ValueError:
print("your input is not a valid number.Don't ruin my program!")
user_input = ""
while user_input != "exit":
user_input = input("enter your days and unit\n")
if user_input == "exit":
break
days_and_unit = user_input.split(":")
if len(days_and_unit) == 2:
days_and_unit = {"days":days_and_unit[0], "unit": days_and_unit[1]}
validate_and_execute(days_and_unit)
else:
print("ERROR,Somthing went wrong")