Answer:
The solution code is written in Python 3
- time_input = input("Enter calling time: (Please enter hour followed with minutes e.g. 14 30): ")
- duration = float(input("Please input duration of call: "))
-
- time_list = time_input.split(" ")
- hour, minutes = int(time_list[0]), int(time_list[1])
-
- COST_PER_MIN = 0.2
- duration = round(duration)
- cost = duration * COST_PER_MIN
-
- if(hour > 12):
- hour = hour % 12
- print("Calling time: " + str(hour) + ":" + str(minutes) + " PM" + " Cost: $" + str(cost) )
- else:
- print("Calling time: " + str(hour) + ":" + str(minutes) + " AM" + " Cost: $" + str(cost) )
Step-by-step explanation:
Firstly, we use input function to get the time and duration input (Line 1 -2). The time input is taken as a string and then we use split method to convert it into individual time component, hour and minutes (Line 4-5).
Presume the cost per minutes is $0.2 (Line 7) and we use the round function to round up the duration to the next integer (Line 8). Next, we apply formula to calculate the total cost of calling (Line 9)
We create if-else statement to check if hour larger than 12, then we print the calling time in PM and then display the cost, else the calling time is printed as AM (Line 11 -15).