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()
If you want to make the user type in a even number and try again if its odd you can use this method.
def main():
numbers = 1
listWithNumbers = []
while numbers < 6:
print(f"Enter nr{numbers}")
num = int(input("Enter number: "))
if num % 2 == 0 or num == 0:
listWithNumbers.append(num)
numbers = numbers + 1
else:
print("we dont take odd numbers here, try again")
n = max(listWithNumbers)
print("The largest number is: ", n)
main()