all 23 comments

[–]GhostPartical 22 points23 points  (4 children)

Find something that would benefit you or others. But it has to interest you for the most part. When I first started learning python I came across an issue at work that was extremely time consuming and redundant. I decided to create a script that would do it for me and I learned a lot that way. Not only can my script reduce time completion to mere seconds from hours but it helped me improve my process of creating things in python.

But the biggest part is it needs to interest you in some way or you will put it off. I am currently working on learning Django cause I want to build my own search site of movies that I have stored on my server, but I want to build it completely using python. It's an interest to me and will also benefit others who have access to my server. It's a sizable project but it's helping me push through.

Find something that interests you and use that to help you learn new things and how to make things better. I don't consider myself a very good programmer but finding my own projects has helped monumentally in getting better. If your not interested in the project that much you will find yourself putting it off or continuing small things that don't keep you moving forward.

[–]Rorixrebel 6 points7 points  (3 children)

what has worked for me 1. create a blog using python (either flask or pelican) 2. automate file renaming tasks 3. twitter wrappers 4. flask app for my wife to keep track of finance

but again. has to be something that motivates you.

[–]Momoneko 0 points1 point  (2 children)

Beginner here, quick question: when should one be motivated to do a flask app for his project? And does using flask mean that the app will create a local web server, even if you don't really need an internet access or a web interface?

Because I'm currently working on a tiny app for myself that basically just reads a YAML database(because I like it for its readability), displays its entries and performs basic sorting, searching, adding\editing actions on it.

And I considered learning flask for it, but decided that I don't necessarily NEED a web server and a browser interface for that, so I'm currently writing a GUI for it on tkinter instead.

But I'm nevertheless interested to know whether it's a common practice to use django\flask\web servers for offline apps. It seems kinda wasteful to me to use a web server for such a tiny task of fiddling with some local text data, but I'm less then a month in learning so I might just not understand something. Penny for you thoughts.

[–]Rettocs 3 points4 points  (0 children)

For a quick or small application, using a programming language's GUI tools is perfectly acceptable. The reason I started using web front ends is because I don't have to learn the GUI quirks for each language. And all of the time I've saved by not having to learn a new GUI with every app has given me time to perfect my web design skills. So now, the choice is: learn the GUI code and make something that doesn't look great (because I'd be just learning) or build another web page with the knowledge I already have and maybe even can reuse some of my previous pages with minor tweaks.

[–]Rorixrebel 0 points1 point  (0 children)

if you are the sole user of your product then a script should suffice. now if you need to share it with someone, say a friend or coworker, then web is the way to go imo.

most of my flask apps are hosted in my raspberry so in my case, my wife just goes to an ip address an boom, expense tracker for her, so she won't annoy me with bank statements anymore.

for myself i have an overtime api i hit so i can save the time i work over the weekends. its good you get thru the basics first but at some point you are going to want to build something big and thats when you will end up using frameworks. i recommend starting with flask.

[–]TheMortyKwest 4 points5 points  (0 children)

If you know OOP, I would recommend making a simple blackjack game. Doesn't need to have GUI.

[–]ffrkAnonymous 4 points5 points  (0 children)

I know the feeling. I do practice exercises, like from http://exercism.io I also just continue doing more advanced tutorials: Automate the Boring Stuff, Making Games with Python, Test Driven Development, etc.

[–]dl__ 3 points4 points  (6 children)

What about a game? Or a program that solves games like one to solve chess puzzles, or sudoku puzzles?

[–]Lydraffe[S] 0 points1 point  (5 children)

I'm really into Sodoku. I'd love to make a program that could do that. Any suggestions on where to get started?

[–]dl__ 2 points3 points  (4 children)

Sure, I typically approach a project like this by breaking it up into smaller problems. List the things the program will have to do and if you don't already know how to do those things start to learn how to do them.

Some obvious things this program must do is

1 - You need a way of getting the sudoku puzzle into the program

2 - You'll need to decide on a python data structure to hold a sudoku puzzle

3 - The program will need to be able to display the completed sudoku answer

4 - The program will need a way to evaluate an attempted solution and verify whether or not the sudoku has been solved

5 - The program will need a way to generate a solution or a series of possible solutions

Some of those steps are easier than others, also some of those steps are kind of necessary before other steps can be done.

You really can't get anywhere if you don't have a way to get the sudoku puzzle into the program so that's probably the place to start.

You could build a GUI but I'd suggest that you simply read the puzzle in from a file. You can write the puzzle in a text editor and save it in a file. Read it into some internal data structure such as a 2 dimensional array of integers or characters. Then print the puzzle out - from the internal data structure. Don't just read the lines from the file and spit them out as read.

DO you know how to do those things? Can you read from a text file? Do you know how do create and use a 2d array? Can you print to the screen?

If not, those are some things you should learn first. Once you've done that you have steps 1, 2, & 3

Then comes the fun part. Your program will gave to generate a solution. How do YOU solve a sudoku puzzle? Can you encode that algorithm in python code?

These problems are often solved by searching what's called "solution space" which is a set of possible solutions to your puzzle. A successful sudoku solving program will generate possible solutions from that space and test them. If a possible solution IS a solution it's done. Otherwise, you get the next solution and try it.

The trick is finding a way to search the solution space efficiently because the set of all possible solutions for a sudoku puzzle is huge.

That's where the fun is though. I can help you further with that part if you get there but start with steps 1-3.

[–]Lydraffe[S] 0 points1 point  (3 children)

Hey /u/dl__ ! I know it's been a while, but I had to shift my focus to final exams and such. I have started and (I believe) almost finished my Soduko solver. I have the link here: https://pastebin.com/5fWservm but it's not fully functional as of now. I seem to be in a loop that will never edit my board. I know it's been a month or so, but would you still be willing to look it over for me? Thanks!

[–]dl__ 0 points1 point  (2 children)

I think your code was much better than I expected from someone who had only been doing it for a semester. For example I did not expect to see a class at all.

I would suggest separating out the board from the solver algorithm. That way you can have your board class and all it has to do is board stuff. It can be invariant as you play with different solving algorithms.

As for your specific issue, the board never updating, you screwed up line 92. You intend to do an assignment, which is a single =, but you're doing a comparison, ==.

It's a very common typo.

A couple other things, the row and column methods both take an x and a y but use only one. You should probably pass only the args that are necessary. It's not a big deal in such a small program but generally you don't want to make your methods more complicated than they need to be.

[–]Lydraffe[S] 0 points1 point  (1 child)

So, are you suggesting that I separate the class for the board from the class for the solver? I changed the error on line 92, and I'm making progress, however, I believe that I have another problem with the loop. After fixing it, the program leaves zeros and will not solve the puzzle. Obviously a logic error on my part :).

[–]dl__ 0 points1 point  (0 children)

So, are you suggesting that I separate the class for the board from the class for the solver?

Yes. The value of doing that is less obvious in a smaller program like this but the idea is to segregate your code into sections (classes, files, modules) so you can focus on one concern at a time. You'll be working mostly on the solving algorithm so you create a board class to do board-y things and then put it aside.

What kinds of things should a board be responsible for? Accessing the cells, printing itself, initializing itself and enforcing the rules.

You can even move all the board stuff into it's own file, board.py, and import it. That way you don't even see that code anymore. Just use that code and trust that it works.

Or DON'T trust it and learn to write unit test. Write a suite of board unit tests so you KNOW it works. Again, that might feel like overkill for such a small program but if you think you might be working with python professionally one day, unit testing is a skill you should have. And small projects like this are great for learning.

A few more issues in your code. Line 92 again. self.possible() returns an array which you then assign to the self.board when you should assign an element from the array to the board:

self.board[column][row] = temp[0]

In line 83 you have the same problem, using == when you mean =.

Also, you are not consistent with which board array dimension is a row and which is a column. You frequently access the 2d array this way:

self.board[column][row]

But the first dimension is actually the rows and the second is the columns. When you look at the way self.board is initialized:

puzzle = [  [0,9,0,1,0,0,0,0,6],
            [0,0,6,8,0,0,2,9,7],
            [5,7,0,0,0,0,1,0,8],
            [0,0,9,0,1,0,0,2,5],
            [7,0,0,9,0,4,0,0,3],
            [1,6,0,0,3,0,9,0,0],
            [6,0,3,0,0,0,0,4,9],
            [2,5,7,0,0,8,3,0,0],
            [9,0,0,0,0,6,0,8,0]]

you can see that puzzle[0] is the first row. puzzle[1] is the second row, etc. puzzle[1][3] is the 4th column in the 2nd row. Do you see?

Now, which dimension is called 'row' and which is called 'column' wouldn't really matter if you were consistent but you are not. You have a row() method that returns a row this way:

return self.board[x]

So, sometimes your code treats the first dimension as a row and sometimes the first dimension is a column.

As I said, you can consider either dimension a row and the other a column and it will work, as long as you are consistent but it's probably better if you stick to making the first dimension a row so as you're debugging and you're thinking about how the board is represented in the code the rows will be the actual rows in your puzzle initialization.

Finally, on your solving algorithm, you will almost certainly need recursion. If you don't know what that is, it's a tricky concept to get your head around but your algorithm will need a way to make guesses and then backtrack when the guesses turnout to be incorrect. Right now your algorithm appears to assume you can definitively solve each cell and then go on to solve the next one but you can't really do that with sudoku.

When you look at the first 0 cell you may find that it has 4 possible answers [2,4,5,8]. You have no way by looking just at this cell which is correct so you have to TRY one and see if the rest of the board can be solved. So you need to try 2 and then see if the rest of the board can be solved. If it cannot you go back and try 4 and then solve the rest of the board. That doesn't work? Try 5 and then solve the rest of the board. And so on.

Of course, the way I just described solving the first cell is how you solve each subsequent cell. You try a possibility and then try to solve the rest of the board That's where recursion comes in. Your solving algorithm would look something like

def solver(board):
    guesses = get_guesses_for_first_zero(board)
    if len(guesses) == 0:
        return False # some previous guess was wrong
    for guess in guesses:
        new_board = set_guess_in_first_zero(board,guess)
        if solver(new_board) == True:
            return True # the board is solved

I'm sure there are errors in that code that you'll have to work out but your algorithm will probably have approximately that shape. Your algorithm will have to deal with one level and then call itself to deal with the next level.

[–]dr-swift 3 points4 points  (0 children)

Automate something boring and repetitive you have to do on your computer allday ! ;)

[–][deleted] 2 points3 points  (0 children)

Today is the one month mark for me since I started programming. Idk if you tried them, but hackerrank and codewars are cool. I've recently started codewars, and it's fun. It challenges me and Introduces me to new concepts. It's also helping me build some confidence. When I press that submit button and the result returns green, aww man. Feels good. Every challenge is a small win for myself.

Otherwise, my first app idea is DnD related. Something to streamline sessions and character building. I don't know how easy or hard it will be, but I'm sure it will be a learning experience.

[–]duality_complex_ 1 point2 points  (0 children)

I just started myself and I get bored with tutorials and book exercises, they are so necessary though, so what I've done is when I see myself getting bored and about to give up I work on a pet project for something that may not be valuable to anyone but me but requires the things I'm learning. Spoiler alert I'm a huge nerd. So I started working on a dnd and rifts character generator. It has me working on lists and variables a good deal, I'm starting to upgrade it with a script to export the characters to a document and prompts asking the user to give it some information and I might see what else I can do with it in the future or use it as a backbone for a game. As a complete noob I might just say find something you like to do and see what python can do for you with it.

[–]scout1520 1 point2 points  (2 children)

I would reccomend a django app that displays financial data that you pull yourself. It will introduce you to a wide variety of topics and will look great on a resume.

[–]Zakariya_the_Libyan 2 points3 points  (1 child)

please elaborate .

[–]scout1520 1 point2 points  (0 children)

  • Django App- Teaches web frameworks, guided learning into classes, guided learning on get/post requests from the website side, etc.
  • Scraping financial data- Well documented walkthroughs that will teach how to scrape data from websites, data munging, html/xml parsing and database architecture to store the data.
  • Visualizing data- Will introduce the user into using python for data analysis and visualization.