I would like to be able to display or print a count of the number of names that were inputted and display this when the user gets out of the loop by pressing any key other than "y".

For example: Number of patients processed : 4

How could I create a counter and where does this counter need to be inserted into the following code.

Thank you

def main():
    again = 'y'
    while again =='y':
        total = 0.0
        results = []
        print
        name = raw_input("Enter Patients Name: ")
        num_test = input("Enter number of test to average: ")
        for x in range(num_test):
            test = input("Enter Glucose Meter Reading: ")
            results.append(test)
        for value in results:
            total += value
            average = total / len(results)
        print
        print 'Average test result: ',average
        again = raw_input('Add another Patient ' + \
        '(Enter y for yes): ')
main()

You would want to initialize the counter to 0 before your while loop like my_count = 0 and then near the end of the loop contents you can add a my_count += 1 (which is equivalent to my_count = my_count + 1 )

commented: Soved it easily +1

Thanks jlm699. I appreciate the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.