2024-03-23 02:03:13 (edited by Dan Gero 2024-03-23 02:04:09)

Right. So I've been working at this Python thing on and off lately, and so far, I'd say I'm doing OK. I figured out how to do this:

a, b = 0, 1
while a < 420:
  a, b = b, a + b
  print(a)
if a > 420:
  print("Oh no's, too much weed!")
elif a == 420:
  print("Double rainbows all across the sky!")
else:
  print("Hey, where's the weed at? I need it!")

A bit silly, I know, but that's just my personality.

Anyway, I know I'm at the point where I can start making some very basic programs. The problem is, I know how the puzzle peaces work by themselves, but I'm not fully certain about all the various ways they can potentially fit together to make a completed and functional puzzle. I'm really not sure how else to explain my issue. I don't know if it's a creative thing, or if I'm just so new at this thing that I simply don't have the skills to know all the various ways I can make these peaces fit yet, and it'll just take some time.

I guess what I'm asking is, can anyone suggest some super basic programs I can start working on without giving any code examples so that I can try to work these programming mussels a bit more? Also, advice on how to be more creative would help as well. I'm putting emphasis on the no code examples thing, because I'll never learn if people write this stuff for me. I know I can do this; I just need a bit of a lift.

Discord: dangero#0750
Steam: dangero2000
TWITCH
YOUTUBE and YOUTUBE DISCORD SERVER

2024-03-23 03:08:26

Everyone always starts with a guess the number game (look up the random package) where it tells you whether your guess is too high or low (you can always win in log2(r) where r=max-min, so it is also an introduction to the concept of binary search)

If you conquer the Django tutorials, which are well-written, you can be putting together basic web apps/apis pretty fast if that's your thing.

There are tons and tons of online textbooks. I haven't needed such in a decade so I can't name any specific ones.  But those do have homework exercises in them, everything from I could do it in under a minute through to it would be hard even for me.

At some point you'll need to want to build something.  If you just want exercises the internet is overflowing with them but anything larger than one file, that's a project and not really something we can necessarily give you.

For what it is worth if you do not yet understand lists, dicts, and classes you won't get far and should go do that before going much further.  The first two are mandatory.  Classes is because that's a common thing to use in Python and a lot of other languages but you can get by without them for a while.

My Blog
Twitter: @ajhicks1992

2024-03-23 05:07:36 (edited by felix_weber 2024-03-23 05:13:50)

Actually, I partly agree with you, I said partly because there is no need for extensive knowledge to write class, rather, people can write classes for small things. The difference in writing a class may depend to the algorithm. For example, someone who wants to write an NPC must write a class. Otherwise, they can proceed with list and conditions, but sure writing a class may be the last thing you need to learn, it depends on the function/library you want to perform with the class. However, op is more of a starting point, so I would like to advise staying away from programs that write code for you, as it will make you lazy in learning programming in the future.

Regards,
Felix.

2024-03-23 05:21:57

No, quite simply you cannot read much Python code on the internet or basically any intermediate resource without understanding classes.  It's not optional but it can be delayed a bit.  Only a bit though.  You can write without them to some extent, but unless you're using global variables or have functions taking 50 parameters or want the really ugly dict syntax you kind of need them.  Python overloads the term because there's classes as in object oriented programming and then there's classes as in I needed a bag of data, and while you can avoid OOP you really do want them to just be able to have a bag of data to store all the fields that might be on a player or something.  No one wants to do:

player["health"]

All freaking day.  You can, but none of the helper tools that can catch mistakes will find a typo there and you've got so much extra punctuation and just, god, no.

(for the advanced coder modern Python has dataclasses, a module to automatically generate tons of boilerplate "Thhis is a thing with health and mana" on your classes, there are lots of tools to make it less annoying, but it is still a class at the bottom).

My Blog
Twitter: @ajhicks1992

2024-03-23 07:08:44

No, what I mean is, someone who understand a bit about writing classes could make a walking NPC but not more, that's just an example, but as I said, it requires knowledge as you also mentioned, to write a  complicated class.

Regards,
Felix.

2024-03-23 09:48:27

I tend to agree A little more with what camlorn said since python is object oriented. If you don't know what that concept is, you might have a hard time in the future and things might become a little harder to understand. Making a program without lists or dictionaries would not look that great IMHO.

To answer OP's question, get an idea of what you would like to have built at the end of the day. It could be anything from A scheduler for tasks to an expense tracker, start small. That's how you climb the stairs. Don't make the mistake to flat out start making A game that is too complex Like camlorn said, try out guess the number. Then implement tries. Then implement A points based system that scores points based on howmany times you correctly guessed the right number. With those points you can purchase hints that provides the range in which the number more or less is... I know it can get complicated and what I said is probably not all worth it for now, hope it helps.

best regards
never give up on what ever you are doing.

2024-03-23 10:19:25 (edited by magurp244 2024-03-23 10:38:17)

I might suggest making a text adventure, since that can potentially challenge you with things like combat scenario's, inventories, or traveling between locations. As mentioned though, you should have a good hold of the basics, which includes lists, functions and classes, which help make things easier when working with larger amounts of data or code so you can more easily scale things up. For example, making an Orc monster class, and then just calling that every time you want to spawn/despawn a new enemy.

You could also try looking into Software Design or Game Design resources for how to better structure your code for larger projects.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2024-03-23 11:46:25 (edited by CAE_Jones 2024-03-23 11:50:26)

Game assignments I got in school:
Tic-tac-toe (with the computer following logical rules, which I might not have done right since I won more easily than expected but whatever)
guess the number
Stupid Wizard, a short text adventure where we actually didn't have to write it from scratch, but we did have to edit what we were given to follow the design the assignment provided.
That last one inspired this, if I remember the URL correctly. And then I learned from how that went wrong and started on DLE. Then learned from how that went wrong to make ... was it this" Eh, I don't thinkt one works anymore, anyway.

I contest the need to use classes for NPCs. Classes and OOP make complex projects so, so much easier, but they are not necessary outside of, like, Java, where literally everything is a class. Evidence ... uh... I really should look up these URLs before writing th... either this or this, I think? Which was made for a sighted audience and is filled with inside references and wingdings. So... have ... fun... with ... that... ?

... Gah, I did it again! yikes
Try tic-tac-toe, to work with arrays and simple AI. Then try a simple text adventure for string parsing and player states. Then try a simple text adventure with classes.
Yep. Let's do it that way.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2024-03-23 19:00:05

@8
Python does not have structs.  You need classes because that is your struct.  Your other options are dicts which have horrible syntax and zero tools to catch mistakes, functions with tons and tons of parameters, or global variables.  Not that Dan knows what structs are yet either, especially since Python doesn't have any, but can you all stop arguing this point?  If you all do want to argue this point show me your nice alternative.  I will take it as a given that anyone competent enough to argue against this point for real understands that tons of global variables are bad and while that's fine as a really new coder it should be moved away from as fast as possible.

But seriously you can't even have a vector with x/y/z fields without classes so... Like fine don't use methods, don't use OOP, shrug, but...

My Blog
Twitter: @ajhicks1992

2024-03-23 21:44:09

I started recently tackling this by figuring out what task am I performing manually that I could automate. The first thing that came to mind was patching Hearthstone with the community mod, and determined what that looked like. I broke it down into simple steps: how do I download a file? How do I unzip a file? How do I perform basic filesystem operations to move said patch files to the Hearthstone installation directory?

Truthfully, that project was mostly just plugging in code I found online, but it has taught me a few things along the way, namely that I'm fine with grabbing some code online to help, some good ways to improve on design, how to make it accessible, etc etc. So, maybe it's helpful to approach it from the angle of making a task easier for yourself or others.

What game will hadi.gsf want to play next?

2024-03-23 23:18:20

Haha, half my job used to be grabbing code from the internet and modifying it to fit my solution.  The only reason it isn't these days is because we don't use a lot of third party dependencies on the stuff I'm working on lately.  Still our Rust monorepo has I think over 100 dependencies.  If Python made dependencies less terrible it'd be the same there, instead you get a few really big ones and a huge set of built-in things but it's kinda the same thing in the end.

My Blog
Twitter: @ajhicks1992

2024-03-24 00:02:41

@9: Didn't say anything about using dicts for everything being a good idea. Or arrays, I guess, but that's generally worse. Though, maybe it's worth trying something with global dicts for everything, just because playing with something that seems powerful enough on its own, only to run into the weaknesses naturally, can sometimes be a better way to learn than just being told. But yeah, obviously using classes effectively is the end goal.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2024-03-24 03:12:27

@12
Yes but player left bracket quote stats quote right bracket left bracket quote health quote right bracket

Need I say more? There's tons of other shortcomings of that but if you are a screen reader user fucking hell.

My Blog
Twitter: @ajhicks1992

2024-03-24 06:23:30 (edited by Ethin 2024-03-24 06:24:46)

Yeah no thanks. Using arrays instead of dictionaries would be even worse -- now you don't know what each index means. I mean, you could use constants but at that point you've got nearly the same character verbosity, if not more, and no safety guarantees unless your language actually guarantees that run-time checks are implemented. Just use classes, tagged types, structs, or whatever composition mechanism the language provides. Much easier and safer. (I won't even mention how multi-dimensional arrays are horrible on the processors cache...)

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2024-03-24 07:18:24

Eh, I was thinking something more like stats["player"] / stats["enemy"], but it's not like you're wrong. We're talking about practice projects for learning the ropes. Learning the rules is one thing; understanding why the rules are rules is another.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2024-03-24 11:12:06

yeah but you keep skipping over one thing, most people when getting started with one thing get very very used to it and find it really really really hard to do something else another way, like the bgt folks for example, I know many of those who moved to python, but keep doing the every screen = a new while loop system, even though I keep giving them examples it's hard for them to get used to, So teaching them somehting bad from the beginning only to tell them it's bad later is just way too counterproductive.

2024-03-24 18:11:27

most of the beginner project i've done in practice usually included oop and data structures to an extent, then their are the small games which were more like algorithm practice for search,sorting and all that stuf.
one way you can go about it by building small projects that you mite be interested on, you can equire a lot of knowledge this way, break what the project structure into smaller parts that you can easilly solve, you can optain code samples form the web to asist you  further, that was one of the ways i used to complete some web projects when i had a python job once, although i mostly lean more towerds reading documentations.

And as anyone who's gone mountain climbing knows ,The serene snow-covered peaks that look so tranquil from a bdistance, Are the deadliest
sound is my vision
i rarely check my private messages on the forum, so if you want to contact me please use my email, or dm me  at oussama40121 on tw

2024-04-09 04:13:24

One thing that I find fun is random text generation. Making a body of text and replacing it with random options or input. You could try making mad libs stories, or allowing the user to type options for it to choose from. Other people said text adventures which is a good idea.

from collections import namedtuple

FieldEntry= namedtuple(‘FieldEntry’, ['location’, ‘pet’, ‘activity'])
journal= FieldEntry([input() for n in range(len(FieldEntry._fields))])
text= f’Today I took my pet {journal.pet} to the {journal.place}, and we had a good time {journal.activity}!'

You could make a script that creates an html document using short symbols to replace bigger code blocks, such as the letter h for heading followed by 1-6, or the letters s, n, or p, for same, next, or previous level referring to the last heading created.

last_heading= 1
document= ‘<body>'
text= input()
#the first 2 letters signify a heading, then a space, and the heading title
if text.startswith(‘h’) and text[2]== ‘ ‘:
  document+= add_heading(text)
document+= ‘</body>’

def add_heading(text: str):
  global last_heading
  text= text.split(‘ ‘,1) #index 0 is the heading and index 1 is the title
  if text[0] in set(‘123456’):
    last_heading= int(text[0])
  elif text[0]== ’n’:
    last_heading+=1
  elif text[0]== ’p’:
    last_heading-=1
  elif text[0]!= ’s':
  return ''
  return f’<h{last_heading}>{text[1]}</h{last_heading}>'

you could build a rock paper scissors game where the user can make their own items.

import random

def rps(player: str):
  game= {
    'r': {'name': 'rock', 'strong': {'s'}, 'weak': {'p'}},
    'p': {'name': 'paper', 'strong': {'r'}, 'weak': {'s'}},
    's': {'name': 'scissors', 'strong': {'p'}, 'weak': {'r'}}}
  if choice not in game:
    return 'Invalid choice. Available choices:\n'+ ', '.join(list(game.keys()))
  cpu=random.choice(list(game.keys()))
  if cpu== player:
    return f'Hmm, I also chose '+game[cpu]['name']+'. It\'s a draw!'
  elif cpu in game[player]['weak']:
    return f'Well done, '+game[player]['name']+' beats '+game[cpu]['name']+'. You won!'
  elif cpu in game[player]['strong']:
    return f'Too bad, '+game[cpu]['name']+' beats '+game[player]['name']+'. I win!'
  #neutral choice
  return game[player]['name']+' and '+game[cpu]['name']+' are equal. It\'s a draw!'

choice= input()
print(rps(choice))

My first actual project was the rhythm rage level creator. Over time I learned more concepts and learned to attach them to the existing project, or figured out what I needed to learn once I had an idea of what I wanted to do with the project.
I actually didn’t think about the level creator immediately. I just started with the thought of, "let’s make an empty script and build”. I barely knew the difference between a sound object and sound pool, so the first task was making a sound object play, and then exit. The next step was adding a key that plays something with the sound pool while that sound object was playing.
Next what I did was have it write a file with example text every time I pressed the key, along with the sound it played. It was only after this, that I realized how simple it was to create a level creator for rhythm rage. Well, not a good one, but one none the less.
When first starting out, the code is a mess. Just copying and pasting similar lines of code because you want functionality more than anything. It’s a bad habit, but we all do it in the beginning. Next thing I know, aliases are apart of the script. I just added a global variable that changes each time you press space, with aliases enabled.
One thing to know is that I didn’t have a timer yet, I used the sound object to tell what position in milliseconds the key was pressed.
Then I posted it to the forum to get feedback, because I didn’t know where to go from there. People gave me a bunch of suggestions, and I thought about how I could add them. I didn’t know how arrays worked, so that and timers were things I had to figure out. Then dictionaries. And so on. Eventually, the project got more capabilities, and still ended up a pile of garbage and terrible code. Then one day I switched to python and abandoned the project.
I just messed around with random components until an idea struck me. Something simple that I could accomplish immediately, though knowing it would start out pretty much useless, and admittedly still ending up just as useless haha.
But because this is python instead of bgt, you aren’t forced to make a function with a while loop consisting of key press if statements in order to test things or make projects. In fact I don’t recommend doing that. My first python project was attempting to write my own game engine, using pygame because of course it would be. It was a massive failure and waste of time. Sure I built some things with it, but I didn’t learn much and it only served to continue reenforcing those bad habits from bgt. A lot of which I still have.
I built the sequence storm announcer tool using the engine, and that was a nightmare. I’ve since expanded to learning from different sources such as NVDA addon development, and discord bots. Though it’s just for a hobby, not serious development, so I’m not progressing much with programming.

2024-04-09 04:17:05

About the second recommendation... there's markdown for that.

2024-04-09 05:29:27

Yeah should have clarified only do this as a learning exercise lol. It’s not a good practical solution for a real project.
The first idea isn’t great beyond being an exercise either. That’s what jinja2 exists for, unless you want to make your own app entirely like I did for my mad libs discord bot. I’m  using beautiful soup to build that, with custom html tags and attributes.