Yash12345
Badges: 9
Rep:
?
#1
Report Thread starter 2 months ago
#1
Anyone who's good at Python coding?
I could really do with any tips/advice.
Thanks
0
reply
MagnumKoishi
Badges: 21
Rep:
?
#2
Report 2 months ago
#2
(Original post by Yash12345)
Anyone who's good at Python coding?
I could really do with any tips/advice.
Thanks
I've got ~5 years experience with python, ask me anything
0
reply
winterscoming
Badges: 19
Rep:
?
#3
Report 2 months ago
#3
(Original post by Yash12345)
Anyone who's good at Python coding?
I could really do with any tips/advice.
Thanks
Tips an advice on what kinds of things? There's some good general Python advice here which you might find useful: https://docs.python-guide.org/writing/style/

Otherwise, it's better to ask specific questions about programming/Python or whatever you happen to be struggling with. Although two things I can think of which are certainly worth doing if you haven't done so already:

(1) Use a good IDE (Integrated Development Environment -- i.e. code editor tools) to write your code with. Python has one which comes out-the-box called IDLE but it's not a very nice/friendly IDE. There's a much better tool called JetBrains PyCharm, which has a lot of features that are really helpful when learning for being able to understand what's happening and providing some built-in automatic assistance where/when you're going wrong. For example, decent auto-completion, error highlighting, mouse-over help, etc. These kinds of things are really useful while you're learning and can make the whole experience less frustrating (Community Edition is available free: https://www.jetbrains.com/pycharm/download/ )

(2) Make sure you learn how to use the debugger. a debugger will help you understand what your program is doing when it's running by letting you step through line-by-line and view what's happening with variables in your program (among other things). This is really important for diagnosing problems in your code, and can also be useful just for checking your assumptions (i.e. that what you "think" is happening really is happening). PyCharm has a few good guides on learning to use the debugger -- it should take you about 15 minutes to figure out how to use it, but it's something which could save you hours/days so it's an extremely important to skill to learn as early as possible:
https://www.jetbrains.com/help/pycha...plication.html
https://www.jetbrains.com/help/pycha...thon-code.html
0
reply
Yash12345
Badges: 9
Rep:
?
#4
Report Thread starter 2 months ago
#4
(btw it's not python 3 or 2.7)I can do simple code and can understand all the loops and syntax but I can't do extended programs/maths problems like finding Fibonacci numbers,etc.I am doing IGCSE Edexcel Computer science next year, so I'm preparing for that.
0
reply
Yash12345
Badges: 9
Rep:
?
#5
Report Thread starter 2 months ago
#5
(Original post by MagnumKoishi)
I've got ~5 years experience with python, ask me anything
How would I go about making a game, like Tictactoe for example.
0
reply
MagnumKoishi
Badges: 21
Rep:
?
#6
Report 2 months ago
#6
(Original post by Yash12345)
How would I go about making a game, like Tictactoe for example.
If you're wanting it graphical, tkinter works decently for something like that. Use either the canvas and draw a representation of the game board with lines, or a grid of labels with images and on-click events bound to them.

Alternatively, you could simply print a representation of the game board using things like O, X, | and _. This will save getting familiar with tkinter
Last edited by MagnumKoishi; 2 months ago
0
reply
winterscoming
Badges: 19
Rep:
?
#7
Report 2 months ago
#7
(Original post by Yash12345)
(btw it's not python 3 or 2.7)I can do simple code and can understand all the loops and syntax but I can't do extended programs/maths problems like finding Fibonacci numbers,etc.I am doing IGCSE Edexcel Computer science next year, so I'm preparing for that.
(Original post by Yash12345)
How would I go about making a game, like Tictactoe for example.
I'd say that a Fibonacci program is probably much simpler than a tic-tac-toe game, If you can understand what the Fibonacci sequence is and how to calculate it "by hand", then it's a matter of examining it to look for the pattern and then describing the rules. It turns out that the rules of the fibonacci sequence are simple, which means it only needs a few lines of code to implement. Tic-tac-toe also has rules and patterns, but there are a lot more rules for tic-tac-toe compared with the fibonacci sequence, which means there's more code to write, and more things to figure out how to do 'by hand' before you can write the code.

But the point really is that the 'hard part' of programming (regardless of whether you're writing a game, solving a maths problem, making a web app, etc.) is always in the the mindset of problem solving and computational thinking. The same methodology and way of thinking about solving a Fibonacci problem is also going to help you write a tic-tac-toe game.

To create the game, you need to spend time understanding what you're actually creating and what the game really is before you sit down to write any code. It's impossible to write code for something unless you fully understand the thing you're writing code for in the lowest level of detail.

In terms of a game, the first thing you need to do is be able to describe the rules of the game in exact detail - i.e. imagine you're trying to explain what the game is and how the game works to a 5-year-old child and to walk them through the entire game step-by-step, describing to them exactly what's going on at each point along the way. (As it turns out, explaining the rules of tic-tac-toe in that level of detail using plain English actually isn't anywhere near as simple or obvious as you might think).

For example - when the game starts, what do they see?
What does the first player do after the game starts?
What happens after the first player has made their first move? what do they see on the screen?
What does the second player do after the game starts?
What happens after the second player has made their first move? what do they see on the screen?
etc.

Then start looking at other rules such as what happens if the board is filled up?
what does it mean to win/lose? i.e. how would you describe the patterns and reasoning that decides whether a player has won or lost? What do they see on the screen?
Also remember that you neeed to define all the concepts that the game uses in terms that relate to something you can express in Python -- e.g. What is a board? what is a row or line? what is an O or X? etc.

Before you begin writing any code, make sure you have plain-English answers for all of these things -- answering those questions isn't actually as easy as it sounds. It's important to be able to think in the same terms as a computer. Remember that computers only understand really simple low-level concepts, and the Python language has a limited set of concepts as well, so you need to look at ways of using the programming concepts in Python to represent parts of your real problem.

Start out with small, simple problems. Don't try to solve everything at once. Problem-solving is a case of "divide and conquer" -- i.e. every big, difficult, complicated problem is actually just a series of smaller, easier, simpler problems; you just need to break it down into those smaller problems until they all become simple/obvious and easily solvable.

You might even end up writing some really long-winded, repetitive copy+paste code as well, and that's actually OK. Sometimes you need to write code the long way before you can visually spot the pattern and look at a way of generalising it. That's another good case for starting out with the easiest possible thing, because usually the easiest way to write code involves creating something which looks very inelegant -- being able to spot patterns in code and see ways of generalising to make the code more elegant is a slightly 'higher level' way of thinking which will start to feel more natural as you spend more time writing code.

When a problem feels too big and complicated, just break it down into small pieces and limit yourself to just solving one small part of a problem at any one time. You might even decide to write lots of very small throw-away programs which each only solve one small part of the game or try things out to see what works and what doesn't. For example:

How do you want to keep the current state of the game and board in memory? (Usually whenever you have multiple related "things" in memory then you need a list of something)
How do you want to display the board to the user?
How do you want to get an input from the user?
Are you doing a one-player or two-player game? (Hint: A two-player game is much easier to start with, you can add an automated/computer player later)
How do you want to implement the concept of players taking turns?
What logic might you use to check the state of the board for win/loss/draw?

Try to code the simplest thing you can do which solves the smallest part of a problem and get that working before moving onto the next thing. Also, always write small pieces of code and run the program very frequently (don't write dozens of lines of code all at once and then find yourself drowning in loads of errors, that is never a good way to write a program. When you have loads of errors in one program, you'll end up wasting hours chasing/fixing problems and probably end up throwing it away to start again). It's normal to write code in tiny steps -- programming is an "iterative" thing, whereby you gradually build up a solution from small pieces step-by-step. Nobody ever gets the whole solution right first time, but you might get little bits of it right.

Also, I mentioned the debugger in my previous post -- you will find running your code in a debugger. and using breakpoints will be really useful if your program doesn't work in the way you expect -- its good for spotting subtle mistakes like simple "off by one" counting errors, as well as NOT/AND/OR logic errors, and errors with empty variables, etc.

Also, don't forget that Google and StackOverflow will give you loads of answers to specific questions -- Typing asking questions like "How do I do [...] in Python" will get you a long way. e.g. "How do I count items in a list using Python?" or "how do I compare multiple variables in Python?" etc. Chances are when you're stuck someone else will have asked the same or similar question many times before on StackOverflow.
Last edited by winterscoming; 2 months ago
0
reply
Yash12345
Badges: 9
Rep:
?
#8
Report Thread starter 2 months ago
#8
Thanks for the help! Really appreciate it.
1
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

University open days

  • University of Bristol
    Undergraduate Open Afternoon Undergraduate
    Wed, 23 Oct '19
  • University of Exeter
    Undergraduate Open Day - Penryn Campus Undergraduate
    Wed, 23 Oct '19
  • University of Nottingham
    Mini Open Day Undergraduate
    Wed, 23 Oct '19

Have you made up your mind on your five uni choices?

Yes I know where I'm applying (154)
59.46%
No I haven't decided yet (60)
23.17%
Yes but I might change my mind (45)
17.37%

Watched Threads

View All