Please check and advise other ideas or options

#!/usr/bin/env python

coding: utf-8

# U.S. Medical Insurance Costs


#develop lists

import csv

with open(‘insurance.csv’) as insurance_data:
key_data = insurance_data.readline().strip(’\n’)
key_list = key_data.split(’,’)
age =
sex =
bmi =
children =
smoker =
region =
charges =
for line in insurance_data:
values_data = insurance_data.readline().strip(’\n’)
values_list = values_data.split(’,’)


Calculate Average Age

def average_number(lst):
total = 0
for i in lst:
total += i
return round((total / len(lst)))

print(“Average Age of patients”, average_number(age))


#Count data

def count_data(type_data, lst):
count = 0
for i in lst:
if type_data == i:
count += 1
return count
#count total females and male
print(“Number of female patients”, count_data(‘female’,sex), ‘Number of male patients’, count_data(‘male’,sex))


#Count most smoker based on any input variable
print(“Number of smokers”, count_data(‘yes’,smoker), ‘Number of non-smokers’, count_data(‘no’,smoker))

Count Female smokers and male smokers

count_female_smoker = 0
count_male_smoker = 0
lst_sex_smoker = list(zip(sex, smoker))
for patient in lst_sex_smoker:
if patient[0] == ‘female’ and patient[1] == ‘yes’:
count_female_smoker += 1
elif patient[0] == ‘male’ and patient[1] == ‘yes’:
count_male_smoker += 1
print(‘Female Smokers’, count_female_smoker, count_female_smoker100/count_data(‘yes’,smoker),’% of Total smokers’)
print(‘Male Smokers’, count_male_smoker, count_male_smoker
100/count_data(‘yes’,smoker),’% of Total smokers’)


#Population per region
print(‘Southwest patients’, count_data(‘southwest’,region))
print(‘Northwest patients’, count_data(‘northwest’,region))
print(‘Southeast patients’, count_data(‘southeast’,region))
print(‘Northeast patients’, count_data(‘northeast’,region))


average insrance costs

print(‘Average insurance costs’, average_number(charges))


Cost of insurance for a string category

def cost(category,category_list):
list_check =
list_check = list(zip(category_list,charges))
total_cost = 0
for patient in list_check:
if patient[0] == category:
total_cost += patient[1]
return round(total_cost)

print(‘Smokers insurance costs is’, cost(‘yes’, smoker))
print(’ vs non-smokers insurance costs’, cost(‘no’,smoker))


#Check average BMI and distribution
count_greater = 0
count_smaller = 0
for i in bmi:
if i < average_number(bmi):
count_smaller += 1
elif i > average_number(bmi):
count_greater += 1
print(‘Number of patients smaller than BMI average of’, average_number(bmi),‘is’,count_smaller)
print(‘Number of patients greater than BMI average of’, average_number(bmi),‘is’,count_greater)


#insurance cost as per BMI

lst_bmi_cost = list(zip(bmi,charges))
insurance_greater_bmi = 0
insurance_lower_bmi = 0
for i in lst_bmi_cost:
if i[0] < average_number(bmi):
insurance_lower_bmi += i[1]
elif i[0] > average_number(bmi):
insurance_greater_bmi += i[1]
print(‘Insurance costs for greater BMI than average’, average_number(bmi), 'is ',round(insurance_greater_bmi)) print('Insurance costs for lower BMI than average', average_number(bmi), 'is ',round(insurance_lower_bmi))


#insurance cost as children
lst_children_cost = list(zip(children,charges))
insurance_with_children = 0
insurance_with_nochildren = 0

for i in lst_children_cost:
if i[0] > 0:
insurance_with_children += i[1]
insurance_with_nochildren += i[1]

print(‘Insurance with children’,round(insurance_with_children), ‘vs Insurance with no children’,round(insurance_with_nochildren))

Can you please read this and post your formatted code?

Or, push the .ipynb file to Github so it is formatted?

Unlike other programming languages, Python relies on indentation in the code for the compiler to read it.