Learning Python

Anybody else learning Python right now? I have coded in Perl for 30 years, but I think it’s time to learn Python, so I started taking the “Automate the Boring Stuff with Python” course on Udemy. One of the examples given was a tic-tac-toe game, and since I just watched WarGames yesterday I decided I would write a tic-tac-toe game. I have never written a game in my life, either.

Interestingly I got to the “Put X in the center square” part of WarGames at exactly the same time as my course got to putting X in the center square, and I took a pic of it. I didn’t plan it that way, it just worked out that way.

Anyway, if anyone wants to see and laugh at my code, it’s on GitHub: https://github.com/ataridude/learning-python/blob/master/tic-tac-toe.py

Considering I’ve never written Python before, I think this is pretty good.

Also, I know of only one issue with the program: I don’t trap a bad move, so if you enter garbage for the move, it crashes. As far as I can tell, it properly detects a win or a stalemate, though, which is cool.

Constructive feedback welcome. Comments of “Convert it to OOP” not welcome. :slight_smile:

Edited to add: I have updated it to catch an invalid move.

2 Likes

Sounds like you and I started using Perl around the same time. :slight_smile: It’s so versatile, and I love its regular expression capabilities.

Python and I never got along, so I avoid it. I am in the minority.

You should take a look at Julia (the language), which might appeal to you. It uses a just in time compiler that makes it nearly as fast as C, and it has syntax similar to Python, but it uses braces instead of indents (Perl like, and important to me). Search Julia vs Python for some interesting reading, and good luck!

1 Like

Thanks, I’ll check that out. I am learning Python because I need it for work. So far I’m finding some cool things, but also several annoyances. I don’t understand OOP (despite years of trying to get it), so a lot of this is gibberish to me.

2 Likes

Similar, I’m trying to learn JavaScript so I can create something for work (on the side). I was looking at python as well, but I’d read that a lot of people who do full stack development ( web front and js.node back ) stick with JavaScript. Cool app tho :+1:

2 Likes

I posted about this, including the pic I mentioned, and thought others might like to see it.

5 Likes

I just always think… you could solve this with functional/procedural programming… why need OOP?
Maybe it’s a generational thing? :rofl:

3 Likes