133k views
1 vote
The program asks the user to enter the time the call is made (day, evening, or night) and the duration of the call (a number that can have one digit to the right of the decimal point). If the duration of the call is not an integer, the program rounds up the duration to the next integer. The program then displays the cost of the call. Run the program three times for the following calls: (a) 8.3 min at 1:32 P.M. (b) 34.5 min at 8:00 P.M. (c) 29.6 min at 1:00 A.M.

User Maxfowler
by
3.6k points

1 Answer

7 votes

Answer:

The solution code is written in Python 3

  1. time_input = input("Enter calling time: (Please enter hour followed with minutes e.g. 14 30): ")
  2. duration = float(input("Please input duration of call: "))
  3. time_list = time_input.split(" ")
  4. hour, minutes = int(time_list[0]), int(time_list[1])
  5. COST_PER_MIN = 0.2
  6. duration = round(duration)
  7. cost = duration * COST_PER_MIN
  8. if(hour > 12):
  9. hour = hour % 12
  10. print("Calling time: " + str(hour) + ":" + str(minutes) + " PM" + " Cost: $" + str(cost) )
  11. else:
  12. 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).

User Ali Alqallaf
by
3.5k points