Python Program Find Maximum Number in List

By | March 23, 2020

Topic: Python Program Find Maximum Number in List

# Python program to find largest  
# ( maximum )number in a list
# using max() function
  
def main():
    
    # create empty list so that user will input at runtime
    number_list = [] 
  
    # ask the user to input n / how many numbers? 
    num = int(input("How many numbers you wish to Enter in list:")) 
  
    # Use for loop to enter n numbers in the list 
    for i in range(0, num): 
        item = int(input("Enter Number "+str(i+1)+" in List: ")) 
        number_list.append(item) 
      
    # print maximum number in list using max(list) function
    print("The enterd List is:",number_list)
    print("The Maximum number in list is:", max(number_list))

main()    

Output

How many numbers you wish to Enter in list:5
Enter Number 1 in List: 890
Enter Number 2 in List: 561
Enter Number 3 in List: 111
Enter Number 4 in List: 656
Enter Number 5 in List: 555
The enterd List is: [890, 561, 111, 656, 555]
The Maximum number in list is: 890

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *