Practical Class #01 - First Programs
(22/09 to 26/09)
Exercises for submission
In what concerns the "exercises during classes" component of the evaluation, the exercises that you can submit for this class are:
Deadline for submission: October 11th (submit to IP's Mooshak)
You are encouraged to talk to the professors and your colleagues if you encounter difficulties.
However, any more direct help that you have received from other colleagues or LLMs should be acknowledged in the comments of the code you submit.
After the deadline the problems will still be available on Mooshak, but the submissions will not count towards your grade.
Each practical class is worth 10% of your final component for exercices during class. Since there will be 11 classes with submissions, you can achieve maximum grade even without doing all classes.
For a problem to count you must pass all tests (that is, to have an accepted). Even if you solve all problems, the maximum on one class is 100%.
To obtain 100% it will always be enough to solve the main exercises.
With the exercises in this class you will develop the following skills:
- Explore the IDLE IDE and the Python interpreter for your first Python programs
- Manipulate simple data and algebraic expressions
- Handle Input and Output
- Debug simple programs
If you feel stuck, go back and revise the lecture T02: The basics
0) Setup of practical classes
The DCC labs will have Linux, which will be the operating system also used on the practical tests. Start by looking into useful applications (ask the teacher if you need any help).
- Firefox/Chrome: web browsers
- IDLE: Python programming environment
If you are on your own machine, go ahead and install Python. In classes, we will be using Python version >=3.10 (this means any version from that value onwards will do just fine). IDLE will most probably be installed by default if you a standard Python installation.

Perfect! Now it's time to create our first program. Follow the instructions below to setup a very, very basic Python environment:
- Open a terminal, and write
idle
. This should start the IDE.
- Try out IDLE. This is its interpreter (you can identify it by the
>>>
symbols just before the cursor) See if it is capable of doing some basic math
- Go to "File -> New File". This is where we will write scripts. Write
print("Hello World!")
. Notice how when you click "Enter" it does not run anything, but rather change line? This is a good hint that you are writing a script.
- Go to "Run -> Run Module" (or just F5). This requires saving the file. Feel free to select the name of your first script. Notice how the file extension is .py? This means the machine can recognise it as a Python script.
- Did it work? If so, great! Otherwise, check all the previous steps... Or immediately panic and beg the teacher for help. It's the first class, anyways ;)
You are now ready to start programming!

Some Notes:
- You can use other editors or IDEs if you want, such as VSCode, Emacs or Vim, but for this course IDLE is more than enough!
- You can call the command python to access the interpreter on the command line
- You use the comamnd python file.py to run a Python script that is saved on a file with the name file.py
1) My first Mooshak submissions

On this course we will use Mooshak to automatically evaluate your Python code (see Mooshak's help).
- For all your submissions you can visualize the detailed
result obtained in each of the test cases made. It is also
possible to access any public tests for which your program did
not receive the Accepted veredict.
For seeing all this detailed feedback you only need to click the result of your submission that appears underlined in the listing.
To access the system you can use your login (with the word "up")
and password that was sent to your institutional email (message sent on the 21st of September with the title "[IP] Mooshak password - login")
(if you have trouble accessing it, send a message on discord to @PedroRibeiro or ask your practical class professor)
In this problem the goal is to make your first submissions in Mooshak, all for the [IP001] Hello there. The problem statement will also be available inside Mooshak. Always start by carefully reading the problem statement given!
- Start by submitting an Accepted in Mooshak. Create a file called for instance ip001.py, write the code and test it in your computer. Is it doing what you expected?
- After a correct submission you should now experiment with some common errors to see the behavior of Mooshak in these cases:
- Try to get a Compile Time Error - for instance you could create code that does not close any open parentheses } and resubmit.
- Try to get a Wrong Answer - for instance you could change the output to produce a different message than what was requested
- After having this errors your list should be something like this picture. (the number to the left of the result is the number of correct tests)
2) Reading my first input

For this exercise you will be solving the problem [IP002] Bond, James Bond!.
- Read the problem, code and submit an Accepted solution. Don't forget to test first on your computer!
- After a correct submission experiment with another type of error, by adding one more instruction to read something from the output (e.g. read three lines of input).
Submit to Mooshak to see what happens and to discover your first Runtime Error.
If you click on the underlined result itself you can see a detailed table containing the result of each test case and also giving you the first input where your program failed, and the respective expected output (should be something like this picture - note on how the observations report what error was obtained).
Here are a couple more notes about Mooshak on this course:
- You can experiment on your own computer with the provided input examples to check the result (just copy+paste the inputs)
If you saved your python script in a file named ip002.py and your input in a file named input.txt, you can also use redirection to feed your program with that input using a line such as python ip002.py < input.txt
- All problem statements will follow roughly the same format, specifying the problem, the input, the output, the constraints and giving at least one input example and its corresponding output.
- You do not need to verify the constraints on your code. On the contrary, the constraints give you guarantees on the input that will be given to your program. You can assume the test cases we will feed your code obey the constraints (e.g. the word sizes will never be larger than 20).
- All the lines of input and output should be terminated with the newline character (including the last line). Failure to do this can result in a Presentation Error.
- You should only output what is given in the statement. Any extra output will can your code be marked as incorrect.
- You can click on the submission number on the left of each listing row to recover your submitted code.
- If you press on more... you can see an interface for seeing submissions that allows you to select only a certain student, a certain problem, etc.
- If you submit a file that is exactly the same as one that you already submitted, Mooshak will not accept and report a Duplicate submission.
3) Training with Mooshak

Read the statements, code and submit Accepted solutions to all of the following problems. Don't forget to test first on your computer!
- [IP003] Check Please
- [IP004] Circle Math
Extra exercise for consolidating your knowledge [extra]
IP Mooshak classes will usually include at least one extra
exercise that you can use of you want to keep testing your
knowledge of the material. For this class we propose another
problem for you will only need what you learned in lecture #02 - The Basics.
Solve and submit the following problems:
Challenge exercise [challenge]
IP Mooshak classes will usually include one challenge exercise, which can be much harder the previous ones and might even need knowledge that was not given explicitly on the course.
However, since this is the first challenge, it is almost of the same difficulty of the previous exercises.
Happy coding! 😊 (if you finish everything and want more practice exercises, let us know on discord - we have plenty more to give you 💻)