How to print out the max and min without a definite list?

This is the assignment: #Write another program that prompts for a list of numbers as above and at the end prints out both the maximum and minimum of the numbers instead of the average.

def program2():
  sum=0.0
  count=1
  greatest_so_far=None
  smallest_so_far=None

  while True:
    number=input("Please write a number. When you are done, please write 'done.'\n")
    if number=="done":
      break
  try:
    number=float(number)
    sum=sum+number
    count=count+1 
    if number==None or number>greatest_so_far:
      greatest_so_far=number
    elif number==None or number<greatest_so_far:
      smallest_so_far=number
    
  except:
    print("Please use only numbers.")
    #Why doesn't it work when I write "continue" here?
    
  print(sum,count,greatest_so_far,smallest_so_far)

program2()


Read more here: https://stackoverflow.com/questions/67377503/how-to-print-out-the-max-and-min-without-a-definite-list

Content Attribution

This content was originally published by David KT at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: