Introduction to Programming 2025/2026 (CC1024) - DCC/FCUP

Practical Class #03 - Functions (06/10 to 10/10)


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 25th (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:

  1. Explore function definition and function calling
  2. Explore argument passing and return statements
  3. Practice breaking down problems into smaller tasks by writing functions
  4. Explore how functions help in reusing code and making it more organized
  5. Consolidate your knowledge of coding, debugging and problem solving

If you feel stuck, go back and revise the lectures T02: The basics | T03: Conditionals | T04: Program Flow | | T05: Functions | T06: More Functions


1) My first function submission

On this class all the exercises involve implementing a given function. Here are some notes:

To help you get started, here is some Python source code that serves as an example solution to the first problem from this class:

# [IP023] All in one
# Example Solution

# The function definition
def sum(a,b):
    return a+b

# Examples from problem statement
print( sum(1,2)   )
print( sum(-3,3)  )
print( sum(32,10) )
print( sum(7,8)   )
print( sum(4,-7)  )

# Some more examples
print("--------------------------")
print(sum(-1000,1000))
print(sum(40,3))

When executed, this python code will output the following, confirming it answers as expected:

3
0
42
15
-3
--------------------------
0
43

You are now ready to submit! 😺


Submit an Accepted the following problem. Don't forget to test first on your computer!


2) Testing your knowledge of Python and functions

Can you now do some exercises on your own? 😉


Read the statements, code and try to submit Accepted solutions to all of the following problems. Don't forget to test first on your computer!

  1. [IP024] Freezing in here
  2. [IP025] All in one
  3. [IP026] And may the odds...
  4. [IP027] Like the frog, get it?
  5. [IP028] Factorial Frenzy


Extra exercises for consolidating your knowledge [extra]

Loved the main exercises and craving for more? These extra problems are here to help you sharpen your skills and reward those that are coding for the love of learning 😄


Read the statements, code and try to submit Accepted solutions to the following two problems. Don't forget to test first on your computer!

  1. [IP029] Collatz Sequence
  2. [IP030] Numerus Maximus!


Challenge exercises [challenge]

You've made it this far, and now it's time for the final challenges! Push yourself, you've got this!


Read the statements, code and try to submit Accepted solutions to the following two problems. Don't forget to test first on your computer!

  1. [IP031] Just an Average Party
  2. [IP032] The Prime Suspects

Happy coding! 😊