Search code examples
pythonmaxmin

i wrote this code to find the largest and smallest (int)number but it does not work


I wrote this code to get an input of several int numbers and write the smallest and largest of them but the code does not work.

numbers=[]    
num=input('enter your number')    
Int_num=int(num)    
Int_num.append(numbers)    
print('maximum number is:',max(numbers))    
print('minimum number is:',min(numbers))

Solution

  • In order to get a sequence of numbers:

    numbers = []
    while True:
      number = input('Enter a number or enter q to exit: ')
      if number == 'q':
          break
      else:  
          numbers.append(int(number))
    
    print(f'Max: {max(numbers)}, Min: {min(numbers)}')