esubmit
We recommend using PyCharm for general Python programming in CS 2400. Steps for setting up an MSOE windows laptop:
python --versionYou should see a version greater than 3.0 listed. If you get a "command not found" error, do the following:
\Users\your login\AppData\Local\Programs\Python\Python39If all else fails, you can open a Command prompt and type
cd \ dir/s python.exeThere may be multiple versions; use the folder names to determine the best match.
python.exe
are available at the command
prompt: start by clicking on the Windows
button in the lower
left corner and typing "path". Click on "Edit the system environment
variables" and then Environment Variables...
python.exe
(that you found above).
python
now works.
python -m pip install -U mypyThis will install a Python type checker that we will use below.
main.py
they already
created, but this is helpful.
You now have a running Python project using an IDE that's reasonably similar to ones you've used before. But there are some features that we will use in some courses that you may not be familiar with.
You can set breakpoints in PyCharm and run your code in a debug mode just like IntelliJ. However, entering the data over and over again slows down debugging. The following steps walk you though debugging the provided code and give you tools that can help debug other Python projects.
input1.txt
in the Project Browser. The total
for these three quizzes is 25.5, so the average is 8.5. Confirm this
works by selecting Edit Configurations... from the Run
menu, selecting the main
configuration, and clicking on
the input1.txt
Note: since the working directory is the directory
that contains input1.txt
, it would seem
that input1.txt
would be sufficient in this box. Apparently
it is not.
input2.txt
. Running your code
on this shows an average of 7.0. However, this is incorrect!
Open input2.txt
in PyCharm and notice the non-negative
scores are 8, 7, 0, and 6. The average of these four numbers is 21/4 =
5.25. Let's fix this.
quiz.py
and set a breakpoint at line 20.
input2.txt
, click on the debugging icon. The program
will stop after having computed nonnegatives
.
self
to examine the attributes. The
scores array includes all five numbers, so that seems ok.
nonnegatives
. Note this array has just three
entries; it should have four. See if you can find the error in computing
this array.
nonnegatives
is computed, re-run
your program to confirm it is correct. Note you should re-run both cases
and maybe test a few additional ones!
Review the methods in Quiz
. These use Python type
hints to document the parameters and return values. Type hints are
powerful; they allow a static type checker to catch many mistakes in
code. This is especially important in CS 2400 where we will process many
different sorts of values. A static type checker can save you hours of
debugging.
The first step is to enable a static type checker in PyCharm:
int
and note that the second return is
highlighted. Hover your mouse over it to see that this is returning a float
(which it should be!) rather than the int. Restore the return type
to float
.
Note that you can also perform a static type check at the command
prompt. Using Windows File Explorer, browse to the folder containing your
project, click on the folder box at the top, and
enter cmd
. This will start a command prompt at that
location. Type
python -m mypy main.py quiz.pyto run the type checker. Assuming your computer is set up to do so, it should print "no issues found in 2 source files". However, it is not critical if this works; the information available in PyCharm should be sufficient in most cases. There are some errors that the PyCharm version will not catch; for example, try changing the line
num = float(line)in
read_quiz
to
num = lineand note PyCharm does not report the incorrect type of list being passed to the
Quiz
constructor but that python -m mypy
(at
the command prompt) does.
Demonstrate that you have completed this exercise by submitting your
solution (main.py
and quiz.py
)
to esubmit.msoe.edu
as exercise1. Most students will have
used esubmit before, but if you have not or need a refresher then
see this page.