samedi 15 août 2020

Python - Find The Largest Odd Number

The assignment is to print the largest odd number among 3 variables --- x, y, and z. Now my code can find the largest odd number, but how can I tell the answer is associated with which variable (x, y or z)?

    x = 123414121
    y = 148723221240982121
    z = 10420116234121
    
    numbers = [x, y, z]
    oddnumbers =[]
    
    for i in numbers:
        if (i%2!=0):
            oddnumbers.append(i)
    
    if len(oddnumbers) == 0:
        print ("none is odd")
    else:
        print("largest odd number:", max(oddnumbers))

Aucun commentaire:

Enregistrer un commentaire