Find the greatest number in a list of numbers

后端 未结 7 1998
我在风中等你
我在风中等你 2020-11-29 02:04

Is there any easy way or function to determine the greatest number in a python list? I could just code it, as I only have three numbers, however it would make the code a lot

相关标签:
7条回答
  • 2020-11-29 03:00
        #Ask for number input
    first = int(raw_input('Please type a number: '))
    second = int(raw_input('Please type a number: '))
    third = int(raw_input('Please type a number: '))
    fourth = int(raw_input('Please type a number: '))
    fifth = int(raw_input('Please type a number: '))
    sixth = int(raw_input('Please type a number: '))
    seventh = int(raw_input('Please type a number: '))
    eighth = int(raw_input('Please type a number: '))
    ninth = int(raw_input('Please type a number: '))
    tenth = int(raw_input('Please type a number: '))
    
        #create a list for variables
    sorted_list = [first, second, third, fourth, fifth, sixth, seventh, 
                  eighth, ninth, tenth]
    odd_numbers = []
    
        #filter list and add odd numbers to new list
    for value in sorted_list:
        if value%2 != 0:
            odd_numbers.append(value)
    print 'The greatest odd number you typed was:', max(odd_numbers)
    
    0 讨论(0)
提交回复
热议问题