largest_number = 0
number1 = int(input("Enter the first number: "))
number2 = int(input("Enter the second number: "))
number3 = int(input("Enter the third number: "))
if number1 > number2:
if number1 > number3:
largest_number = number1
Please annotate your code (make the line above and below the code have three backticks). Without it, the indentation can’t be seen, which is important.
Please tell us what input you think should trigger that codpath, what output you expect for it, and what output you are getting instead.
“i am trying to write a program that finds the largest of 3 number with different methods, i tried to script it with this way” but everytime i enter the third number value; i get 0 for the <largest_number> Variable
i am trying to write a program that finds the largest of 3 number with different methods, i tried to script it with this way" but everytime i enter the third number value; i get 0 for the <largest_number> Variable
Line 1 sets largest_number to 0. For that input, your logic never resets it, so it reports zero. It might be better to get rid of that first line and just have your program generate an error rather than a wrong number.
You have 3 if/elif/elif stanzas. Only one can be entered. Since 2 > 1, you enter the second stanza. But then 2 is not bigger than 3, so the largest_number is not reset. The if/elif/elif is complete and you drop to the print line, never resetting the largest number.
The second elif isn’t entered because the first elif is entered. You can only enter one.