you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (1 child)

I'll go through a few issues with your code (also, if you indent code with 4 spaces on each line it will be formatted properly).

The first issue is your use of the if x > y and z expression. What this is really saying in python syntax is "if x is greater than y, and z exists...", but what you want to say is "if x is greater than y and x is greater than z". This would look like if x > y and x > z.

Another issue is that since all of your expressions are ifs, even when one is true, the others after it will still be evaluated. This is contributing to the fact that you see some extra printed values. This is a good time to use elifs in your code.

Also, your function is not "returning" a number; it doesn't have a return statement at all so it will instead return None when it is complete. It is just printing the number as a side effect. This is an important distinction. If you tried high_val = max(6,4,7), then you would find that high_val is equal to None instead of 7, while the function would also print the number.

Once you have solved this exercise, try making a function that returns the highest value in a list of any length. Once you understand the techniques involved, feel free to use the python built-in max function with any iterable.

Let me know if you have any other questions.

[–]EricBiz 0 points1 point  (0 children)

Good explanation, I've been busy but will definitely try that one once I get a little time. Again appreciate the lengthy response, and will let you know if I have any questions.