When I try to run this code, I get incorrect maximums and minimums. Could anyone tell me how I can fix it? I am not allowed to use 'max' and 'min'.
UPDATE: I have updated the code and it still doesn't work properly. UPDATE 2: The code works now! Thank you so much guys!
minimum=float('inf')
maximum=None
count=0
total=0
number=input ("Please enter the amount of numbers you wish to categorize: ")
while True:
num = input("Enter a number: ")
count+=1
total+=num
if num is None or num < minimum:
minimum = num
if num is None or num > maximum:
maximum = num
if count == number:
break
print "The average of your numbers is ", round ((total / count),2),"."
print 'The largest number is:', maximum,"."
print 'The smallest number is:', minimum,"."
homeworktag to any homework questions.minimumandmaximum, and about the value you should use. Should it be a value you provide, or should it be a value your user provides?/performs truncating division (3/2 == 1). Usefloat(total)/countor(1.0*total/count)or something to avoid this problem in the case of integer input.inputtoraw_input.raw_inputreturns a string; you have to do this to convert it to an int:num = int(num). Also, as mVChr points out, yourbreakstatement is in the wrong place. Think about what happens if your user enters the maximum or minimum number last.int(raw_input( ... ))instead ofinput.