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 18th (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:
If you feel stuck, go back and revise the lectures T02: The basics | T03: Conditionals | T04: Program Flow
1) Conditional Statements
For this first batch of four problems you will mainly explore the usage of conditional statements (such as if, elif and else) and boolean expressions.
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!
We encourage you to speak with your colleagues and with your professors if you need help (including using Discord), but be aware that you should be trying to solve the exercises by yourself!
You get from a course what you invest on it and by actually trying to solve the problems you will learn a lot (including some of the things you will not get correct the first time, which will become lessons you will not forget).
This course is all about "putting your hands dirty" in terms of actually coding, and if you rely on other's code (or tools such as ChatGPT) you will be most of all just fooling yourself... Try to do it and enjoy the rich and dynamic experience we prepared for you! 😊
2) Program Flow and Cycle Instructions
For this second batch of four more problems you will now explore the usage of program flow instructions (such as for, while and range), combined with what you already know.
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!
Again, try to do it it by yourself and revisit the lectures, seeking help and hints if you need help.
3) Leveling up
We now propose two more problems which are still more than doable with what you already learned, but might be a bit more difficult from the point of view of the algorithm associated (so it is more about the idea that just the code and the syntax of Python).
These problems include hints that are initially hidden so that they don't become spoilers if you want to try the problems by yourself first. If you get stuck, click the button to open the hint! 🦮
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!
- Keep three variables while you are traversing the numbers:
. cur
giving the size of the current stretch of identical numbers
. best
with the best stretch length until now
. last
with the last number seen
- At the start, read the first number and assign cur=1
and best=1
(this is where you are AFTER reading the first number: on a stretch of length 1, which is also the best)
- Each time you read a new number:
. if it is the same as the last
number, increment cur
(the current stretch grows)
. if it is different, than cur=1
(you start a new stretch)
- After this, before reading a new number, update the last
number and verify if your best
was improved
- To extract the last digit you only need to... check the remainder of dividing by 10 (n % 10)
- To remove the last digit and keep the other... divide the number by 10 (n // 10)
- You can now make a cycle where you repeatedly do this to keep extracting all the numbers until you reach zero:
Imagine for example that the number is 123. Then:
. 123 % 10 = 3 and 123 // 10 = 12, leaving you with 12
. 12 % 10 = 2 and 12 // 10 = 1, leaving you with 1
. 1 % 10 = 1 and 1 // 10 = 0, leaving you with 0
- All that's left is to keep summing the last digits whyle you are traversing the number, right?
So you enjoyed the main exercises so much, that you want more problems to submit? Don't worry we've gor you covered! Here are some exercises to consolidade your knowledge and to show you are coding for more than simply your grade 😃
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!
So you want one more challenge? Here you go! It is not too hard, but if you can do it you are showing you truly mastered this part of the material!
Read the statement, code and try to submit an Accepted solution to the following problems. Don't forget to test first on your computer!
Happy coding! 😊