Skip to content

Instantly share code, notes, and snippets.

@devpruthvi
Created March 2, 2016 13:26
Show Gist options
  • Save devpruthvi/fd82b2db3dbd86cf34c6 to your computer and use it in GitHub Desktop.
Save devpruthvi/fd82b2db3dbd86cf34c6 to your computer and use it in GitHub Desktop.
import numbers
def getNumber(s):
try:
return int(s)
except ValueError:
return float(s)
flag = True
nums = []
while flag:
try:
num = raw_input('Give a number: ')
if(num == "quit"):
flag = False
elif not isinstance(float(num), numbers.Real):
raise Exception
else:
nums.append(getNumber(num))
except:
print('Only numbers are allowed')
print('Results:\nMaximum = ' + str(max(nums)) + '\nMinimum = ' + str(min(nums)) + '\nSum = ' + str(sum(nums)) + '\nAverage = ' + str(sum(nums)/len(nums)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment