Wednesday, November 16, 2022

Numbers 2 - Python Programming for Beginners Practice Exercise 5

Exercise 5:

Let's assume you are planning to use your Python skills to build a social networking service. You decide to host your application on servers running in the cloud. You pick a hosting provider that charges $0.51 per hour. You will launch your service using one server and want to know how much it will cost to operate per day and per month.

Write a Python program that displays the answers to the following questions:

How much does it cost to operate one server per day?

How much does it cost to operate one server per month?

Solution:

  1. #!/usr/bin/env python3
  2.  
  3. # The cost of one server per hour.
  4. cost_per_hour = 0.51
  5.  
  6. # Compute the costs for one server.
  7. cost_per_day = 24 * cost_per_hour
  8. cost_per_month = 30 * cost_per_day
  9.  
  10. # Display the results.
  11. print('Cost to operate one server per day is ${:.2f}.'.format(cost_per_day))
  12. print('Cost to operate one server per month is ${:.2f}.'.format(cost_per_month))

No comments:

Post a Comment