Home > Software design >  python user to enter 5 even numbers and print the largest
python user to enter 5 even numbers and print the largest

Time:02-26

The question is : Ask the user to enter 5 even numbers then print the largest

and python keep giving me this error idk why (unindent does not match any outer indentation level) I am using python.3 IDLE on Mac

def main():

     num1 = int(input ("First number"))
     num2 = int(input ("Second number"))
     num3 = int(input ("Third number"))
     num4 = int(input ("Fourth number"))
     num5 = int(input ("Fifth number"))
     n = max (num1, num2, num3, num4, num5)

    if n % 2 and n == 0 :
        print ("The largest number is:", max)
    else:
        print ("we dont take odd numbers here")
main()

CodePudding user response:

In VScode it seems like the intendeation was of on rows 3 to 8 so the if-statement didnt work. I made a small change and added the print(f"") and made a few adjustments to the code so it whould work now. Also you print out max witch is a function to get the higest number, and you set the highest number to n. So just print n instead. The if statement should be if n % 2 == 0

def main():

    num1 = int(input ("First number"))
    num2 = int(input ("Second number"))
    num3 = int(input ("Third number"))
    num4 = int(input ("Fourth number"))
    num5 = int(input ("Fifth number"))
    n = max(num1, num2, num3, num4, num5)

    if n % 2 == 0 :
        print (f"The largest number is: {n}")
    else:
        print ("we dont take odd numbers here")
main()

If you dont want to use print(f"") this works too.

def main():

    num1 = int(input ("First number"))
    num2 = int(input ("Second number"))
    num3 = int(input ("Third number"))
    num4 = int(input ("Fourth number"))
    num5 = int(input ("Fifth number"))
    n = max(num1, num2, num3, num4, num5)

    if n % 2 == 0 :
        print ("The largest number is: ", n)
    else:
        print ("we dont take odd numbers here")
main()
  • Related