-1

I'm new to coding, so I'm doing some extraordinarily basic things at this stage. But one thing that's driving me nuts is that Pycharm doesn't appear to be handling the max, min, and sum Python functions properly. For example, if I run something like this in IDLE, I get the proper output:

digits = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
max(digits)

If I run that in IDLE I get an output of 9. If I run that exact same thing in Pycharm, there are no results. No error either...just no results. I just get this:

"/Users/michael/PycharmProjects/pythonProject/venv/bin/python /Users/michael/PycharmProjects/pythonProject/PythonTest.py

Process finished with exit code 0"

The output looks exactly the same as when it runs a block of code properly in PyCharm, but there's no max value returned. There's just a blank line between the filepath and the "Process finished with exit code 0" where the max value should appear. This only happens in PyCharm, which I just downloaded and started using today with success (other than the max, min, and sum functions, everything else I've tried works as expected in Pycharm).

I'm using Pycharm 2023.1 Community Edition and Python 3.11.2. This is bizarre - I've done a number of searches online about this (for the past 30 minutes or so) but found nothing so finally gave up and decided to post this here. It's tough to understand why those functions work everywhere except PyCharm, and why I can find nothing about that online. Any ideas would be appreciated, thanks.

M74d3
  • 61
  • 4
  • If you **save the code in a file** using IDLE and run **the script file**, you will not see output. You see it when you **put the code into the interpreter prompt** that IDLE provides. That is because the output comes **from the interpreter prompt itself, not the code**. It would be really annoying if every time you called a function, it printed something and you *couldn't prevent* that! So, nothing is displayed merely because it is calculated; it is displayed either because an interactive prompt displays it, or the code says to display it. Please see the linked duplicate for details. – Karl Knechtel Apr 02 '23 at 04:13

1 Answers1

1

The problem is that you're not printing the result of the max() function.

If you call a function in an interactive shell such as IDLE, it will display the return result of that function as a convenience.

But running a python script does not do that. If you want to see results, you have to print them.

print(max(digits))
John Gordon
  • 29,573
  • 7
  • 33
  • 58
  • Thanks. I did notice that it showed the expected output when I printed the result of the max function, but I didn't understand why it didn't just show it without the need to print it like in IDLE (and in the book I'm learning from), so I thought it was some sort of bug or unexpected behavior. I didn't know about the interactive shell vs script distinction (a graphic demonstration of my novice status), so that cleared it up. Thanks for the explanation! – M74d3 Apr 02 '23 at 01:06