Exercise 26: Congratulations, Take a Test!
You are almost done with the first half of the book. The second half is where things get interesting. You will learn logic and be able to do useful things like make decisions.
Before you continue, I have a quiz for you. This quiz will be very hard because it requires you to fix someone else's code. When you are a programmer you often have to deal with other programmers' code, and also with their arrogance. Programmers will very frequently claim that their code is perfect.
These programmers are stupid people who care little for others. A good programmer assumes, like a good scientist, that there's always some probability their code is wrong. Good programmers start from the premise that their software is broken and then work to rule out all possible ways it could be wrong before finally admitting that maybe it really is the other guy's code.
In this exercise, you will practice dealing with a bad programmer by fixing a bad programmer's code. I have poorly copied Exercises 24 and 25 into a file and removed random characters and added flaws. Most of the errors are things Python will tell you, while some of them are math errors you should find. Others are formatting errors or spelling mistakes in the strings.
All of these errors are very common mistakes all programmers make. Even experienced ones.
Your job in this exercise is to correct this file. Use all of your skills to make this file better. Analyze it first, maybe printing it out to edit it like you would a school term paper. Fix each flaw and keep running it and fixing it until the script runs perfectly. Try not to get help, and instead if you get stuck take a break and come back to it later.
Even if this takes days to do, bust through it and make it right.
Finally, the point of this exercise isn't to type it in but to fix an existing file. To do that, you must go to this site:
Copy-paste the code into a file named ex26.py. This is the only time you are allowed to copy-paste.
Common Student Questions
- Do I have to import ex25.py or can I just remove the references to it?
- You can do either. This file has the functions from ex25 though, so first go with removing references to it.
- Can we run the code while we're fixing it?
- You most certainly may. The computer is there to help, so use it as much as possible.