配列に文字列を挿入すると、文字列が拒否され、配列でのみ整数が許可される方法を説明するメッセージが表示されると予想されます。代わりに、前に挿入された整数が繰り返されます。
import sys
ArrayWidth = 9
mmWidth = 22
ArrayDivider = '=' * 33
ArrayDivider = ArrayDivider.center(ArrayWidth)
mmDivider = '=' * 28
mmDivider = mmDivider.center(mmWidth)
MaxAndMin = 'Maximum & Minimum'
MaxAndMin = MaxAndMin.center(mmWidth)
Array = 'Array'
Array = Array.center(ArrayWidth)
Numbers = []
while True:
NumberInput = input('Enter a whole number (Exit the loop by pressing "0"): ')
try:
NumberInput2 = int(NumberInput)
if NumberInput2 == 0:
break
if NumberInput2 <= 0:
print('Please enter a number greater then 0.');
continue;
except ValueError:
print("Error. Non-numeric data was entered.")
except:
print("Error with input...")
Numbers.append(NumberInput2)
print('\n'+ArrayDivider+Array+ArrayDivider)
print(sorted(Numbers, key=int),'\n')
print(mmDivider+MaxAndMin+mmDivider)
print('Maximum Number = {}'.format(max(Numbers)))
print('Minimum Number = {}'.format(min(Numbers)))