Question: # Function to calculate energy cost for a given age def calculate _ child _ cost ( age ) : if age < = 4

# Function to calculate energy cost for a given age
def calculate_child_cost(age):
if age <=4:
return 0.5
elif 5<= age <=9:
return 0.6
elif 10<= age <=13:
return 0.7
elif 14<= age <=17:
return 0.8
else:
return 1.0 # Full price for adults
# Function to calculate energy cost based on inputs
def calculate_energy_cost(residents, children, tier):
base_price_per_week =15.0
partner_discount =0.05
tier_discounts ={'B': 0.0,'S': 0.10,'G': 0.15}
# Calculate base cost
base_cost = base_price_per_week * residents
# Apply tier discount
base_cost -= base_cost * tier_discounts[tier]
# Apply partner discount if there are two residents
if residents ==2:
base_cost *=(1- partner_discount)
# Calculate children's energy cost
children_cost = sum(calculate_child_cost(age) for age in children)
# Calculate total cost
total_cost_per_week = base_cost +(children_cost*base_cost)
# Convert to monthly and annual costs
total_cost_per_month = total_cost_per_week *4.34524 # Average number of weeks in a month
total_cost_per_year = total_cost_per_week *52.143
return total_cost_per_week, total_cost_per_month, total_cost_per_year
# Function to get user input and generate energy cost quote
def generate_quote():
print("--------------------------------")
print("Welcome to SmartEco Energy Solutions")
print("--------------------------------")
print("Let us help you manage your energy usage.")
while True:
residents = int(input("Enter the number of residents (1-2): "))
if residents <1 or residents >2:
print("Please enter a valid number of residents.")
continue
children =[]
num_children = int(input("Enter the number of children (0+): "))
for i in range(num_children):
age = int(input(f"Enter the age of child {i +1}: "))
children.append(age)
while True:
tier = input("What tier of energy plan would you like?
[B]asic/[S]ilver/[G]old: ").upper()
if tier not in ['B','S','G']:
print("Please enter a valid tier.")
continue
else:
break # Break out of the tier input loop if a valid tier is entered
weekly_cost, monthly_cost, annual_cost = calculate_energy_cost(residents, children, tier)
print("
Thank you. Your monthly energy cost is:")
print(f"$ {weekly_cost:.2f} per week")
print(f"$ {monthly_cost:.2f} per month")
print(f"$ {annual_cost:.2f} per annum
")
another_quote = input("Do you need another quote (y/n)?").lower()
if another_quote !='y':
print("Have a sustainable day.")
break
# Main function
if __name__=="__main__":
generate_quote()
Draw a flow chart based on the above python program

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!