I'm making a class dataset. In it, I'm trying to set the minimum max and the mean. In my given test, I am asking the user to input as many grades as they would like so what I did, for example in minimum is this..

class Dataset(object):
    def __init__(self, grade):
        self.grade=[]
def min(self):
        try:
            if int(input)<= self.grade:
                return int(input)
        except:
            pass

using this test,

from Dataset import Dataset

def main():
    print('This is a program to compute the min, max, mean and')
    print('standard deviation for a set of numbers.\n')
    while True:
        xStr = input('Enter a number (<Enter> to quit): ')
        if xStr == '':
            break
        try:
            x = float(xStr)
        except ValueError:
            print('Invalid Entry Ignored: Input was not a number')
            continue
        data = Dataset(xStr)
        data.add(x)

    print('Min:', data.min())
    print('Max:', data.max())
    print('Mean:', data.average())
    print('Standard Deviation:', data.std_deviation())

if __name__ == '__main__':
    main()

which was given by the professor. The output is that there is no minimum. What am I doing wrong?

On first blush it could be an indentation error in your class.

sorry, I was actually deleting things in the class. But, its perfectly indented on my idle now.

class Dataset(object):
    def __init__(self, grade):
        self.grade=[]
    def min(self):
        try:
            if int(input)<= self.grade:
                return int(input)
        except:
            pass

Your concept looks strange, as you are anyway putting those in standard set. You initialize self.grade as empty list and it stays so, grade given to Dataset you ignore.

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.