Alright, so today I decided to mess around with scoring in tennis, you know, just figuring out how that whole “love-fifteen-thirty-forty” thing actually works. I’ve watched tennis matches before, but I never really got the scoring system. It seemed so random!
First, I googled “tennis scoring system” to get the basic rules down. Turns out, it’s not as crazy as it sounds, just… different. I learned about “love” meaning zero, and how you go from 15 to 30 to 40, and then to win a game, you need to be at least two points ahead.
My Implementation Process
So, I started by creating a function.
- I used a simple function, to represent the two players.
- Then I added in the current score of each player.
Next up, I needed to figure out how to increment the scores. I made some basic if/else to change score.
For example:
- If player one is on 40 and the score, they won.
- If both players reach 40, then the score is now ‘deuce’.
I kept adding conditions, playing around with different scenarios, like what happens at deuce, how advantage works, and when a game is finally won. It took a bit of trial and error, lots of checking the rules, and rewriting parts of my function,but I am happy with result.
The “love-fifteen-thirty-forty” thing still feels a bit weird, but at least now I have a better grasp of how it all works. Maybe next time I’ll try to figure out how to score a whole set, or even a match! This was a fun little coding exercise to understand a pretty unique scoring system.