- Solutions to CodingBat problems. Contribute to mirandaio/codingbat development by creating an account on GitHub.
- CodingBat code practice. Welcome to Codingbat. See help for the latest. Java; Python; Warmup-1. Medium python list problems - 1 loop.
This is a codingbat solution to makepi from List 1. I strongly recommend you use this as an opportunity to understand the difference between lists and arra.
All solutions were successfully tested on 17 April 2013.
Pay attention to the last line! In Python it is possible to concatenate comparisons, just like you would do it in mathematics. This can lead to much cleaner code. In my opinion, the solution from the website is worse, but not just for that reason alone:
It is not necessary to put “a + b” in line 2 inside parentheses due to the rules of precedence of operators. A less experienced human reader might be able to parse this line more quickly with parens, though. However, you shouldn’t assume that you write code for a complete beginner.
Codingbat Python Answers
What, this looks ugly you say? I completely agree, and there is a much more pleasant solution:
Codingbat Python String 2 Answers
Again, do you go for ugly or nice and clean?