Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My code is encountering an error: Traceback (most recent call last): File main.py, line 18, in age = int(record[1]) IndexError: string index out of


My code is encountering an error: Traceback (most recent call last):
 File "main.py", line 18, in
   age = int(record[1])
IndexError: string index out of range

 

The code an assignment are below: 

file= open("mpox_data.txt", 'r')
for line in file:
data = line.strip().split()


total_mpox = len(data)
men_with_mpox = 0
women_with_mpox = 0
over_65 = 0
men_over_65 = 0
women_over_65 = 0
under_18 = 0
overweight_men = 0
overweight_women = 0

for record in data:
   gender = record[0]
   age = int(record[1])
   weight = int(record[2])

   if gender == 'M':
       men_with_mpox += 1
       if age > 65:
           men_over_65 += 1
       if weight > 210:
           overweight_men += 1
   else:
       women_with_mpox += 1
       if age > 65:
           women_over_65 += 1
       if weight > 180:
           overweight_women += 1

   if age > 65:
       over_65 += 1
   if age < 18:
       under_18 += 1

 

percent_men = (men_with_mpox / total_mpox) * 100
percent_women = (women_with_mpox / total_mpox) * 100

print("1. What is the percentage of men vs. women who have mpox?")
print(f"Of the people who have Mpox, {percent_men:.0f}% of them are males")
print(f"Of the people who have Mpox, {percent_women:.0f}% of them are females")

print("2. How many people over age 65 have mpox?")
print(over_65)

print("How many men over 65 have mpox?")
print(men_over_65)

print("How many women over 65 have mpox?")
print(women_over_65)

print("How many people under the age of 18 have mpox?")
print(under_18)

print("How many men who are overweight by at least 20 pounds have mpox?")
print(overweight_men)

print("How many women who are overweight by at least 20 pounds have mpox?")
print(overweight_women)

 

Almost A Problem

Florida's Governor Ron DeSantis is starting to think that he might have a problem on his hands. This mpox thing does not seem to be going away. In fact, it seems to be spreading. The governor is uncertain as to just exactly what he needs to be doing. He has turned to the USF School of Medicine to get some advice. They, of course, have turned to you to process the monkey pox data that has been collected so that they can provide the governor with some recommendations.

You have been provided with a data file that contains information on the Florida residents who have tested positive for the mpox virus. This data file has the following format:

Gender, Age, Weight, Height, Headache?, Fever?, Exhaustion?, Swollen Lymph Nodes?, Muscle Aches?, Backache?, Chills?, Rash?, Genital Rash?

Note that in the data file, each of the mpox symptoms is represented by either a 0 (False), or a 1 (True).

You are to read in the data from the file, place it into a list, and then answer five questions that the governor needs answers to.

Questions To Be Answered

Based on the total number of people who have mpox, what is the percentage of men vs. women who have mpox?

Question #2:

How many people over age 65 have mpox?

How many men over 65 have mpox?

How many women over 65 have mpox?

How many people under the age of 18 have mpox?

If the average weight of a man is 190 pounds, how many men who are overweight by at least 20 pounds have mpox?

If the average weight of a woman is 160 pounds, how many women who are overweight by at least 20 pounds have mpox?

Sample Data Sets:

The data file that you will be provided with will contain the following data:

Gender,

Age,

Weight,

Height,

Headache?,

Fever?,

Exhaustion?,

Swollen Lymph Nodes?,

Muscle Aches?,

Backache?,

Chills?,

Rash?,

Genital Rash?

Mpox detected?

Assignment Requirements:

 You are only permitted to use the Python commands that we have covered in class so far. Yes, there are many more, but no, you can't use them in solving this homework! (These are: print() math strings I/O IF/Else WhileBoolean And / Or For, Lists,Files, Functions, elif, Break /Continue) 

 

The data file is: 

M 26 180 5.5 1 1 1 1 1 1 1 1 1 1
F 52 190 4.3 1 1 0 0 1 0 1 0 0 0
F 35 135 4.6 1 1 1 0 0 0 1 0 0 1
F 82 125 4.0 1 1 1 0 0 1 1 0 0 1
M 12  85 3.7 1 0 1 0 1 0 1 0 1 1
F 13  90 3.9 0 1 0 1 0 1 0 1 0 1
M 67 270 5.1 1 1 1 1 0 1 1 1 0 1
F 45 210 5.4 1 1 1 1 0 0 0 0 0 1
M 37 220 6.0 1 1 1 0 0 0 1 1 0 1
M 42 250 6.5 1 0 1 0 0 1 1 1 0 1
M 21 160 5.1 1 1 1 0 0 0 0 0 0 1
F 55 205 5.6 1 1 1 1 0 0 0 1 0 1
M 17 160 5.2 1 1 0 0 0 0 0 0 0 0
F 29 120 4.4 1 1 0 0 1 0 0 0 0 0


Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Task Instructions Delete the legend from the Pie chart

Answered: 1 week ago

Question

Calculate 6.6 % of $666.66.

Answered: 1 week ago