I have a working code, but seems to be missing where to add the floating decimal point with changing the entire line. Please see the below as I am looking to get the end result to be $56.00 not $56.0 and seems that I am missing a piece there. # Calculate total amount storage, frequency for a weekdef calculate_backup_size(data_size, backup_frequency): return data_size * backup_frequency # Calculate storage cost for backup storage, cost per gb def calculate_storage_cost(backup_size, cost_per_gb): return backup_size * cost_per_gb # Calculate the backup size, total,cost, cost per gbdef storage_info(data_size, backup_frequency, cost_per_gb, weeks): backup_size = calculate_backup_size(data_size, backup_frequency) total_cost = calculate_storage_cost(backup_size, cost_per_gb) total_cost_weeks = total_cost * weeks return "The total storage needed for backup is {} GB and the total cost for {} weeks is ${} dollars".format(backup_size, weeks, total_cost_weeks) # Positive number checker, will not process if not positive or valid numberdef get_positive_number(prompt): while True: try: value = float(input(prompt)) if value <= 0: print("Please enter a positive number.") else: return value except ValueError: print("Please enter a valid number.") # User enter data size, back up frequency, cost per gb and timedata_size = get_positive_number("Enter the data size (in gigabytes): ")backup_frequency = get_positive_number("Enter the backup frequency: ")cost_per_gb = get_positive_number("Enter the cost per gigabyte: ")weeks = get_positive_number("Enter the number of weeks: ") # Call up storage functionresult = storage_info(data_size, backup_frequency, cost_per_gb, weeks)print(result)
I have a working code, but seems to be missing where to add the floating decimal point with changing the entire line. Please see the below as I am looking to get the end result to be $56.00 not $56.0 and seems that I am missing a piece there.
# Calculate total amount storage, frequency for a week
def calculate_backup_size(data_size, backup_frequency):
return data_size * backup_frequency
# Calculate storage cost for backup storage, cost per gb
def calculate_storage_cost(backup_size, cost_per_gb):
return backup_size * cost_per_gb
# Calculate the backup size, total,cost, cost per gb
def storage_info(data_size, backup_frequency, cost_per_gb, weeks):
backup_size = calculate_backup_size(data_size, backup_frequency)
total_cost = calculate_storage_cost(backup_size, cost_per_gb)
total_cost_weeks = total_cost * weeks
return "The total storage needed for backup is {} GB and the total cost for {} weeks is ${} dollars".format(backup_size, weeks, total_cost_weeks)
# Positive number checker, will not process if not positive or valid number
def get_positive_number(prompt):
while True:
try:
value = float(input(prompt))
if value <= 0:
print("Please enter a positive number.")
else:
return value
except ValueError:
print("Please enter a valid number.")
# User enter data size, back up frequency, cost per gb and time
data_size = get_positive_number("Enter the data size (in gigabytes): ")
backup_frequency = get_positive_number("Enter the backup frequency: ")
cost_per_gb = get_positive_number("Enter the cost per gigabyte: ")
weeks = get_positive_number("Enter the number of weeks: ")
# Call up storage function
result = storage_info(data_size, backup_frequency, cost_per_gb, weeks)
print(result)
Unlock instant AI solutions
Tap the button
to generate a solution








