Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python homework
#1
Hi. I've been trying to finish my homework, but I don't know how to do the last part. I was given a data file called 'BP20dataset.csv' which contains three lists: patientID, age, and BP. The object of the exercise is: Write a code to identify the patients with high blood pressure (> 130 mmHg). The code should generate a list named highBPlist containing the patientID of the patients with BP > 130.
If, and enumerate statements have to be used. This is what I've come up with, but printing the highBPlist returns just []. Thanks in advance

myFile = open('BP20dataset.csv')
patientData = myFile.readlines()
myFile.close()
highBPlist = []
for BP, patientID in enumerate (highBPlist):
    if (i > 130):
        highBPlist.append(patientID)
        highBPlist = patientID.split(",")
Reply
#2
What do you think line 8 is doing?
Reply
#3
(Dec-11-2018, 07:09 PM)nilamo Wrote: What do you think line 8 is doing?
It's supposed to split the values of patientID in the highBPlist with a comma

I changed it a bit, but it now returns an error: '>' not supported between instances of 'tuple' and 'int' for line 6.

myFile = open('BP20dataset.csv')
patientData = myFile.readlines()
myFile.close()
highBPlist = []
for i, patientID in enumerate (patientData):
    if (BP > 130):
        highBPlist.append(patientID)
Reply
#4
Either that's not the code you're running, or that's not the error you get. BP isn't defined anywhere in that code.

(Dec-11-2018, 03:26 PM)MajaW Wrote:
for BP, patientID in enumerate (highBPlist):
    if (i > 130):
        highBPlist.append(patientID)
        highBPlist = patientID.split(",")
I asked about line 8 before, because it doesn't make sense. You're adding a patientID to a list... but then you erase the list and replace it with whatever patientID.split(",") returns. Why iterate over the patients, if you're not going to use any but the last one anyway?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  HELP in python homework makashito 4 3,926 Oct-12-2021, 10:12 AM
Last Post: buran
  CyperSecurity Using Python HomeWork ward1995 1 1,961 Jul-08-2021, 03:55 PM
Last Post: buran
Exclamation urgent , Python homework alm 2 2,305 May-09-2021, 11:19 AM
Last Post: Yoriz
  Homework with python Johnsonmfw 1 1,689 Sep-20-2020, 04:03 AM
Last Post: ndc85430
  Python Homework Help *Urgent GS31 2 2,585 Nov-24-2019, 01:41 PM
Last Post: ichabod801
  Python Homework Question OrcDroid123 1 2,370 Sep-01-2019, 08:44 AM
Last Post: buran
  Python homework / functions sunhyunshine 1 2,454 May-11-2019, 05:37 PM
Last Post: MrTheOne
  python homework help ASAP gk34332 1 2,974 Mar-13-2019, 07:27 PM
Last Post: ichabod801
  Python homework assigment makisha 3 3,280 Feb-28-2019, 10:21 PM
Last Post: Yoriz
  Python Homework Help beepBoop123 2 3,050 Dec-12-2018, 06:25 PM
Last Post: beepBoop123

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020