2

我试图将“房间”中的值作为键,将“acquity”作为字典的值,或者每次代码运行时都将最终值“acquity”分配给一个新变量(它需要运行 32 32 个房间的时间)。我无法弄清楚这一点,对不起,对此很陌生,任何帮助将不胜感激。

def main():

var=0

        while (var<33):

            room=raw_input("Input patient room Number ")




                ##Lists and prints/input for Procedural acuity
            print "1- No Procedures"
            print "2- IV Starts, Foley Catheter"
            print "3- Vitals, Neuro Check, Bladder Scans"
            print "4- Bedside Procedure, Physician post-op, frequent catheterization"
            a=raw_input("Input Procedural Acuity 1-4 ")

                ##Lists and prints/input for Nutritional acuity
            print "1- Setup Self"
            print "2- Ordering Assistance"
            print "3- Feed"
            print "4- Tubefeed, Aspiration Procedures"
            b=raw_input("Input Nutritional Acuity 1-4 ")

                ##Lists and prints/input for Medication acuity
            print "1- Minimal Oral"
            print "2- Moderate PO/IV"
            print "3- Dysphasia/Multi IV"
            print "4- Chemo/GTUBE/Complex IV"
            c=raw_input("Input Medication Acuity 1-4 ")

                ##Lists and prints/input for Mobility acuity
            print "1- Ad lib"
            print "2- Assist of SB"
            print "3- Assist of 1"
            print "4- Assist of 2"
            d=raw_input("Input Mobility Acuity 1-4 ")

                ##Lists and prints/inputs for Behavioral Acuity
            print "1- Calls Appropriately/No Needs"
            print "2- Some Education/ Calls Often"
            print "3- Anxious/ Calls Frequently"
            print "4- New Diagnosis, Calls very frequently, highly anxious"
            e=raw_input("Input Behavioral Acuity 1-4 ")

            a=float(a)
            b=float(b)
            c=float(c)
            d=float(d)
            e=float(e)

            Acuity1= a+b+c+d+e
            print "Patient in room %s, is graded at acuity %s"%(room, Acuity1)
            var= var + 1


if __name__ == '__main__':
    main()
4

2 回答 2

0

在你的开头main(),让我们更改名称以get_roomnumbers_dict添加:

def get_roomnumbers_dict():
    var=0    
    d = {} # this line to initalize the dictionary

    while (var<33):
        .....

在您的功能结束时:

        .....
        Acuity1= a+b+c+d+e
        print "Patient in room %s, is graded at acuity %s"%(room, Acuity1)
        d[int(room)] = Acuity1 # saves to the dictionary
        var= var + 1
        # end of while loop here

    return d # returns dictionary for someone to check acuity and room number

那么在你的代码中你可以简单地拥有:

acquity_by_roomnumber = get_roomnumbers_dict() # and that gets the dictionary
于 2013-04-14T21:12:51.540 回答
0

替换raw_inputinput! 我之前有同样的错误!:P 也添加import sys到顶部!

于 2013-04-14T21:04:04.680 回答