0

My code is very simple. It tells you the largest number, the smallest number, and how many numbers you have inputted before pressing the key 'E'. However, the 'max()' function doesn't consider numbers whose digits are greater than 1. So it ignores range(10,'infinity'). The minimum does work, so I have no idea why it's doing what it's doing. My code is the following:

list1=[]
while len(list1)>-1:
    i = input("Input a number: ")
    list1.append(i)
    if i == 'E':
        break
del list1[-1]
max1 = max(list1)

min1 = min(list1)
c = len(list1)
print('Max: {}'.format(max1))
print('Min: {}'.format(min1))
print('Count: {}'.format(c))
print(list1)

Example:

Input a number: -10
Input a number: 3
Input a number: 4
Input a number: 1
Input a number: 3
Input a number: 5
Input a number: 41
Input a number: E
Max: 5

Min: -10

Count: 7

['-10', '3', '4', '1', '3', '5', '41']

Sorry for the messy format. I don't know how to format text in this website and it did it automatically.

nbk
  • 45,398
  • 8
  • 30
  • 47
  • 1
    Does this answer your question? [python won't count two digit number as highest value](https://stackoverflow.com/questions/31681489/python-wont-count-two-digit-number-as-highest-value) – Stuart Jun 27 '21 at 02:45

1 Answers1

1

You're inputting strings, so they're getting compared for lexicographic ordering, not numerical ordering. Consider

while True:
    i = input("Input a number: ")
    if i == 'E':
        break
    else:
        list1.append(int(i))

By calling int, we convert the value to an integer like 10 as opposed to a string "10" which is really just the digits one followed by zero and whose notion of ordering is different than the one you intended.

Silvio Mayolo
  • 62,821
  • 6
  • 74
  • 116