Skip to content
Advertisement

I’m trying to print the largest number from the inputs that the user gives, but it’s printing the wrong number

Basically, I’m trying to build a code to get the largest number from the user’s inputs. This is my 1st time using a for loop and I’m pretty new to python. This is my code:

JavaScript

When I try running my code this is what happens:

JavaScript

Any fixes?

Advertisement

Answer

So, first things first,

  • the use of max can be avoided, as it is a reserved keyword in python

And coming to your fix, you are comparing it with the value only once in the loop, and you are returning the number, the indentation is the key here. You will have to wait for the loop to complete its job then return the value.

  • There are many inbuilt methods to do the job, Here is your implementation (a bit modified)
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement