r/learnpython • • Jun 18 '20

Python projects for beginners

Hi! I just learned basic python syntax (watched a 4 hour long python tutorial playlist while also doing it myself), what would be some good beginner projects/ programs that i’d be able to make, and second of all, what can i learn next to become better at python?

449 Upvotes

108 comments sorted by

View all comments

16

u/dogs_like_me Jun 18 '20

Start with tic tac toe. Work towards minesweeper.

1

u/OnlySeesLastSentence Jun 18 '20 edited Jun 20 '20

I feel like minesweeper should be relatively easy to program.

Get a location. BombCount=8 If bomb, you dead. If not bomb, for i in range 0,8 if bomb in adjacent[i]: BombCount-=1

Displace BombCount in location. Mark location as visited. If BombCount == 0, then visit each of the adjacent locations and repeat.

Edit: bombs should start at 0 and increase their count. I thought of that backwards.

Project is done now: https://www.reddit.com/r/learnpython/comments/hbbzoa/python_projects_for_beginners/fvevwof

13

u/dogs_like_me Jun 18 '20

You seem to be describing an algorithm for playing minesweeper. I'm talking about programming minesweeper. The game. This entails:

  • building a lattice of 'cell' objects, which will probably need attributes like n_neighboring_bombs, is_visible, is_flagged, is_bomb....

  • Visiting an empty cell should trigger a cascade which reveals all adjacent empty neighbors and the boundary non-empty neighbors (where 'non-empty' means it is bordering at least one bomb, so contains a numeric value). Probably wanna implement this as a graph traversal.

  • "double-clicking" a revealed, unflagged cell, should reveal it's neighbors, potentially triggering a cascade as above.

  • appropriately testing win/lose conditions.

  • possibly maintaining a database of high scores

  • possibly maintaining a database of save states

  • possibly presenting the user with a running timer

  • presenting a visual representation of the board

  • possibly representing the game with a proper GUI (native? webapp?)

  • ...

There's really a lot you can do here. I like to use minesweeper as an exercise to get a tour of language features when I'm learning new tooling. I've coded it up in at least three languages now, two or three different ways just in python.

-1

u/OnlySeesLastSentence Jun 18 '20

I was describing programing it. I didn't list literally everything, but I mean it's pretty easy to make a grid and place a random number of bombs.

The steps I showed were the logic behind what's supposed to happen when someone clicks a spot. You make a matrix and using the logic from from tic tac toe, you search surrounding titles for bombs and place the number as the player plays.

6

u/dogs_like_me Jun 18 '20

Give it a shot, see if it's as simple as you think. Keep in mind, the user can emit several different types of "clicks"

  • Toggle flag on unrevealed cells

  • reveal cell

  • reveal neighbors (if # adjacent flags = cell's reported # neighboring bombs)

Also:

I didn't list literally everything

This is why it's a good exercise for a beginner. It's tractable to get a lightly featured version up with little skill, and if you have the desire/ability to add complexity to your implementation you can.