raw_input和dict

时间:2013-04-14 21:00:21

标签: python dictionary raw-input

我试图将“room”中的值作为键,并将“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()

2 个答案:

答案 0 :(得分:0)

raw_input替换为input!我之前有同样的错误! :P 同时将import sys添加到顶部!

答案 1 :(得分: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