Current Events > ITT: Learning Python

Topic List
Page List: 1, 2, 3, 4, 5, 6, 7, 8 ... 10
SomeLikeItHoth
08/15/21 5:14:46 PM
#151:


Neat little project.

https://realpython.com/python-contact-book/

---
FAM FOREVER.
... Copied to Clipboard!
#152
Post #152 was unavailable or deleted.
SomeLikeItHoth
08/16/21 4:40:47 AM
#153:


Actually, only do that neat little project if you want to test your patience, or don't mind spending a bunch of time looking up how to fix an outdated version of PyQt. And right when I got everything working perfectly, it still won't work.

[LFAQs-redacted-quote]

That is still a good website. I use it when I get stuck on stuff.

---
FAM FOREVER.
... Copied to Clipboard!
SpiritSephiroth
08/16/21 4:30:30 PM
#154:




Got a question here. The code isn't done overall and Im gonna overhaul quite a bit of it. But in the first section, in the "elif" part it looped back in the while loop.

However in the second sections "elif" part, its not looping and just ends. Any ideas why that might be?

---
... Copied to Clipboard!
SomeLikeItHoth
08/16/21 6:21:46 PM
#155:


I have no idea. I rewrote all your code and it worked fine for me. Can you paste the code here so I can try it?

Also, are you using Boss_HP = 10 for anything? Because I didn't see it mentioned anywhere except for at the top.
And instead of saying

You = You - 3

you can simplify it by saying

You -= 3

---
FAM FOREVER.
... Copied to Clipboard!
Questionmarktarius
08/17/21 5:17:18 PM
#156:


A good practice is to avoid hard numbers, and just use variables for everything.
Incrementing/decrementing by 1, and the occasional comparison to 0, are notable exceptions.
... Copied to Clipboard!
SpiritSephiroth
08/17/21 8:43:20 PM
#157:


SomeLikeItHoth posted...
I have no idea. I rewrote all your code and it worked fine for me. Can you paste the code here so I can try it?

Also, are you using Boss_HP = 10 for anything? Because I didn't see it mentioned anywhere except for at the top.
And instead of saying

You = You - 3

you can simplify it by saying

You -= 3

Huh, thats so strange. I booted it up again and it started working now.

As for all the other stuff, I'm going to implement more into the code to make it more complex. Going to have hit counters for everything and a code to keep track of current hp display.

Also thanks for the simplification!

---
... Copied to Clipboard!
SomeLikeItHoth
08/18/21 5:51:13 AM
#158:


SpiritSephiroth posted...
I'm going to implement more into the code to make it more complex
What you could do is start everyone off (including yourself) with a certain amount of HP.

Player = 50
Enemy_# = 10
Boss = 15

And then you could use the random feature to randomize attacks.

Attack = random.randint(0, 10)

Now every time either you, one of the enemies, or the boss uses an attack it'll take a random amount of HP away.

---
FAM FOREVER.
... Copied to Clipboard!
SpiritSephiroth
08/18/21 8:34:54 PM
#159:


SomeLikeItHoth posted...
What you could do is start everyone off (including yourself) with a certain amount of HP.

Player = 50
Enemy_# = 10
Boss = 15

And then you could use the random feature to randomize attacks.

Attack = random.randint(0, 10)

Now every time either you, one of the enemies, or the boss uses an attack it'll take a random amount of HP away.

Thats such a good idea, I don't know why I never thought of randomizing the damage for some reason >_>

Thanks!

---
... Copied to Clipboard!
SpiritSephiroth
08/19/21 6:27:27 PM
#160:


Okay I got a lot of the framework down.

@SomeLikeItHoth I'm thinking of starting from the beginning and making a brand new code. So I'm gonna implement the random attack method you suggested with other actions.

Hopefully I can make something even more complex this time. But I'm happy with the amount I'm learning so far. Its also fun too.

---
... Copied to Clipboard!
SomeLikeItHoth
08/19/21 6:47:07 PM
#161:


You should! Let me know. Right now I'm going through this web scraping project

https://automatetheboringstuff.com/2e/chapter12/

but if I have time tonight I'll also make a quick version of the project you're describing. Just for fun. I already have an idea how I'll write the code out.

---
FAM FOREVER.
... Copied to Clipboard!
SomeLikeItHoth
08/20/21 7:19:40 AM
#162:


I went ahead and made my own little CYOA game.

I forgot how fun these little text games can be to make.

I know I reused some lines of code. I may go back and redo the project using classes / functions. Well see!

Let me know what you think!

https://pastebin.com/EuB748BE

---
FAM FOREVER.
... Copied to Clipboard!
SpiritSephiroth
08/20/21 8:05:03 AM
#163:


SomeLikeItHoth posted...
I went ahead and made my own little CYOA game.

I forgot how fun these little text games can be to make.

I know I reused some lines of code. I may go back and redo the project using classes / functions. Well see!

Let me know what you think!

https://pastebin.com/EuB748BE

Ohhh! I'll give it a go tonight when I'm on python!

---
... Copied to Clipboard!
SpiritSephiroth
08/20/21 9:42:40 PM
#164:


Bump, will try soon. Really feeling dead today.

---
... Copied to Clipboard!
SomeLikeItHoth
08/21/21 7:22:36 PM
#165:


All good!

---
FAM FOREVER.
... Copied to Clipboard!
SomeLikeItHoth
08/22/21 5:46:52 AM
#166:


I know I tell y'all to watch certain videos / read certain articles but this is one you need to make time for.

It's only an hour long but I highly recommend it. It will make using and understanding how Classes work so much easier.

I just finished watching all the videos now + I wrote out all the code but I may watch it again tomorrow.

https://www.youtube.com/playlist?list=PL-osiE80TeTsqhIuOqKhwlXsIBIdSeYtc

---
FAM FOREVER.
... Copied to Clipboard!
SpiritSephiroth
08/22/21 8:54:55 PM
#167:


SomeLikeItHoth posted...
I know I tell y'all to watch certain videos / read certain articles but this is one you need to make time for.

It's only an hour long but I highly recommend it. It will make using and understanding how Classes work so much easier.

I just finished watching all the videos now + I wrote out all the code but I may watch it again tomorrow.

https://www.youtube.com/playlist?list=PL-osiE80TeTsqhIuOqKhwlXsIBIdSeYtc

I'll take a look! I have an important test on Tuesday for something but once I'm done I'll catch up on everything.

---
... Copied to Clipboard!
SomeLikeItHoth
08/23/21 5:30:50 AM
#168:


So I was mad because I spent over an hour trying to figure out why my code wasn't working.

I think I googled 10+ different things and read a bunch of different things on stackoverflow trying to figure it out.

Then by some miracle I figured it out on my own and now I won't go to bed mad.

It was stupid too because I was in a while loop and couldn't figure out why my remove() function of a piece of string in a list wouldn't work. It was so simple but for some reason would not work.

SpiritSephiroth posted...
I'll take a look! I have an important test on Tuesday for something but once I'm done I'll catch up on everything.
Okay bet!

---
FAM FOREVER.
... Copied to Clipboard!
SpiritSephiroth
08/23/21 7:08:05 PM
#169:


SomeLikeItHoth posted...
So I was mad because I spent over an hour trying to figure out why my code wasn't working.

I think I googled 10+ different things and read a bunch of different things on stackoverflow trying to figure it out.

Then by some miracle I figured it out on my own and now I won't go to bed mad.

It was stupid too because I was in a while loop and couldn't figure out why my remove() function of a piece of string in a list wouldn't work. It was so simple but for some reason would not work.

I want to experience this more too. I know how it feels. Cant wait to get back to it after Tuesday.

---
... Copied to Clipboard!
SomeLikeItHoth
08/24/21 5:41:45 AM
#170:


SpiritSephiroth posted...
I want to experience this more too. I know how it feels. Cant wait to get back to it after Tuesday.
Once you start experiencing more OOP (like from the video I linked you) you'll start getting more of those experiences.

---
FAM FOREVER.
... Copied to Clipboard!
SpiritSephiroth
08/24/21 8:03:07 PM
#171:


SomeLikeItHoth posted...
Once you start experiencing more OOP (like from the video I linked you) you'll start getting more of those experiences.

I can continue now that today is done. Gonna catch up with a lot of things!

Also managed to make my computer run faster.

---
... Copied to Clipboard!
Questionmarktarius
08/24/21 8:13:33 PM
#172:


If you're doing RPG type things, that's decent OOP model right there.

Character = an object with HP, MP, EXP, and various stats
Player character = a Character that's accesed by player-driven subsystems, with additional properties that support that
NPC = a Character that's handled by the program itself, with various properties.
... Copied to Clipboard!
SomeLikeItHoth
08/25/21 5:08:41 AM
#173:


SpiritSephiroth posted...
I can continue now that today is done. Gonna catch up with a lot of things!
Finally! Let me know how it goes.

Questionmarktarius posted...
If you're doing RPG type things, that's decent OOP model right there.
Right now I'm working on a battle system using only Python. It's text heavy but I'll condense it once I get everything completed and have the time to go over it line-by-line.

---
FAM FOREVER.
... Copied to Clipboard!
SpiritSephiroth
08/25/21 12:38:34 PM
#174:


Tried out your code, gave me some good ideas on how to deal with code regarding hp. Thanks a lot, time to start with my own!

Liked how you spaced out your code too, it looks so neat and even looks clean when executing it. I should do that more often.

---
... Copied to Clipboard!
SpiritSephiroth
08/25/21 8:32:58 PM
#175:


I've put in a lot of variables to keep track of. Doesn't include all the if statements and while loops I'll be using.

At this stage I'm gonna have to learn to organize my code better.

---
... Copied to Clipboard!
SpiritSephiroth
08/25/21 9:37:14 PM
#176:


Okay this is driving me crazy. Why doesn't "import random" work for me anymore?

The code just greys out and an error comes up. It used to work in my other projects.

---
... Copied to Clipboard!
SpiritSephiroth
08/25/21 10:13:25 PM
#177:


Okay I think I figured it out. The reason why its greyed out is because I'm not using it atm.

Was able to use "from random import randrange" in a variable since I'm going to implement it as part of a code. This is going to be fun. I'm gonna continue this tomorrow!


---
... Copied to Clipboard!
SomeLikeItHoth
08/26/21 6:08:12 AM
#178:


SpiritSephiroth posted...
Liked how you spaced out your code too, it looks so neat and even looks clean when executing it. I should do that more often.
It will save you a headache from trying to read disorganized code, that's for sure.

SpiritSephiroth posted...
The code just greys out and an error comes up. It used to work in my other projects.
What do you use to write code? Pycharm?

SpiritSephiroth posted...
I'm gonna continue this tomorrow!
Keep me updated!

---
FAM FOREVER.
... Copied to Clipboard!
SpiritSephiroth
08/26/21 7:15:41 PM
#179:




What I've done. Far from finished but I think its working. Gonna input a lot more including choices to fight different enemies, increasing XP and levelling up to more stats.

Going to try and implement a magic spell system too. Be able to cure and use magic based on a magic stats.

I was thinking of using the Class function to contain the enemies stats, but I realize you can't really change the variables within a class function without doing a few things first. Thought it'd be easier like this for now.

Edit: Heres the Pastebin

https://pastebin.com/scRqpLdq

---
... Copied to Clipboard!
SomeLikeItHoth
08/26/21 7:25:34 PM
#180:


I'll take a look at it tonight.

---
FAM FOREVER.
... Copied to Clipboard!
SpiritSephiroth
08/26/21 8:20:08 PM
#181:


New problem. Creating that random variable outside of the while loop has made the code pick a number inside of the loop and stick with that one value. If I want to create a truly random interval, I would have to put the random code inside of the while loop.

However that will ruin the level progression, at least in terms of the strength/attack stat. Going to have to figure out a way to keep the stat progression while using while loops.

---
... Copied to Clipboard!
SpiritSephiroth
08/27/21 6:29:45 PM
#182:


Trying to use classes to solve this problem. Gonna give up for today.

---
... Copied to Clipboard!
Questionmarktarius
08/27/21 8:58:14 PM
#183:


Change player_strength to the lower number, then do damage as player_strength + randrange(0,6)
... Copied to Clipboard!
SomeLikeItHoth
08/28/21 6:36:28 AM
#184:


SpiritSephiroth posted...
Trying to use classes to solve this problem. Gonna give up for today.
Once I learned about classes it made organizing so much easier.

---
FAM FOREVER.
... Copied to Clipboard!
Questionmarktarius
08/28/21 6:39:17 AM
#185:


SomeLikeItHoth posted...
Once I learned about classes it made organizing so much easier.
But, you need to know when it's worth going OOP, and when you should just do it all in main().
... Copied to Clipboard!
Questionmarktarius
08/28/21 6:52:48 AM
#186:


My development paradigm has always been "Plan to Fail".
It will fuck up, and deal with it fucking up before that happens.
... Copied to Clipboard!
SpiritSephiroth
08/28/21 6:30:31 PM
#187:


I was out all day, really wanted to get back to coding. Guess I'll have to do it tomorrow.

---
... Copied to Clipboard!
1337toothbrush
08/28/21 9:20:09 PM
#188:


I had forgotten about this topic! Posting here to bring it to the top of my active messages list. I might write an OOP battle system example if you think that'd be useful.

---
... Copied to Clipboard!
SomeLikeItHoth
08/29/21 5:38:43 AM
#189:


Creating my own Flask database to create a blog and was stuck for 20 minutes importing the database. Turns out it was because I had made a typo in my file name when trying to call from flask import db. I googled so many questions trying to figure out what I did wrong.

Questionmarktarius posted...
But, you need to know when it's worth going OOP, and when you should just do it all in main().
I still have trouble with using the import function properly. I was working on a shop to purchase units and set it to its own shop.py file but it wouldn't allow me to call a function from my main.py file due to me calling import from main.py to import the shop.

1337toothbrush posted...
I had forgotten about this topic! Posting here to bring it to the top of my active messages list. I might write an OOP battle system example if you think that'd be useful.
Great idea. Both myself and SpiritSephiroth have been working on our own battle systems. I'm using OOP for mine, so making classes & such but I'm still having trouble with it so I'm taking a break to learn more about OOP. I'll probably get back into that project some time this week, because right now I'm working on a flask database to create a blog. Let us know your ideas + how it goes. @1337toothbrush

---
FAM FOREVER.
... Copied to Clipboard!
SpiritSephiroth
08/29/21 6:27:05 PM
#190:


I think I went off the rails and totally failed in what I was trying to do with these class functions. I need to pick up again and maybe just learn more about them and how to use them before trying to implement them in my code.

Edit: This was all to fix a problem with the while loop and random function, ugh.

---
... Copied to Clipboard!
1337toothbrush
08/30/21 12:13:13 AM
#191:


Alright, I made a quick and awful battle system with poor OOP abstraction: https://pastebin.com/L0EyCgb5

This should at least give an idea of using OOP.

edit: by the way, making this reminded me of how much I dislike Python. Its OOP features just feel awful to work with. I think a large part of that is the dynamic typing but also the syntax is butt-ugly.

---
... Copied to Clipboard!
SomeLikeItHoth
08/30/21 1:15:06 AM
#192:


SpiritSephiroth posted...
I need to pick up again and maybe just learn more about them and how to use them before trying to implement them in my code.
Show us your full code. I can go over it and give a few suggestions.

If you need some more help understanding how classes work, watch that video series I posted. But basically, think of classes as a way to trim down your code. Say you are making an RPG. You aren't going to just have a single character, you're going to have multiple. You could make the character like this:

def character_one(char, health, attack, defense, strength, m_atk, mana):
char = archer,
health = 100,
attack = 20,
defense = 20,
str = 50,
m_attack = 15,
mana = 150,

That's 8 lines of code. Now pretend you want 8 characters. That's 64 lines of code + spacing so a bit over 70 lines of code just for the characters. Using classes cuts down on that because each character will have the same stats no matter what.

class Entity:
def __init__(self, char, health, attack, defense, str, m_atk, mana):
self.char = char,
self.health = health,
self.attack = attack,
self.defense = defense,
self.str = str,
self.m_atk = m_atk,
self.mana = mana,

For every class, the very first method (you call functions inside of classes, methods) will always be the __init__ method, followed by what stats each character will have. Afterwards you simply create a new variable with the amount for each stat.

a = Entity(char=archer, health=100, attack=20, def=15, str=50, m_atk=15, mana=200)
t = Entity(char=thief, health=100, attack=30, def=25, str=45, m_atk=5, mana=0)

And you can call the class as many times as you want, so 8 characters will be in 8 lines of code, rather than 64 lines. Does that make more sense?

1337toothbrush posted...
Alright, I made a quick and awful battle system with poor OOP abstraction
Nah fam. I really like that code. It's very neat. Where did you learn to program? And what other languages do you know?

---
FAM FOREVER.
... Copied to Clipboard!
1337toothbrush
08/30/21 1:46:18 AM
#193:


SomeLikeItHoth posted...
Nah fam. I really like that code. It's very neat. Where did you learn to program? And what other languages do you know?
I started learning the basics of programming while screwing around with RPG Maker 2000 as a kid, but that was a purely point and click interface at the time. Then I picked more up through high school computer science classes and later on in university where I earned my degree in computer science (though for practical programming I learned it mostly through side projects in my spare time). I work as a software engineer, so I keep up to date with stuff.

Languages I know to varying degrees: C, C++, C#, Java, Go, Rust, Python, JavaScript, TypeScript, Turing, Miranda, Racket, Visual Basic, and a laughably small amount of x86 assembly.

Right now I'm highly interested in Zig (https://ziglang.org), however, it's not yet stable and I kinda don't want to learn something that could potentially change drastically while I'm still using it but I do love the design philosophies.

---
... Copied to Clipboard!
SomeLikeItHoth
08/30/21 6:13:40 AM
#194:


Kept working on this Flask tutorial. The guy in the video reorganized his folders due to circular importing, so I did the same thing and copied / named everything perfectly. I deleted my database. I changed the working Python terminal directory to match my new folder. Everything was going smoothly. I created a new database, then I went to import the two classes. That worked too. Then I tried db.create_all(). That didn't work. Nothing worked after that. After spending 45 minutes looking for answers I decided fuck it. Remade a new folder, copied all my files over and reimported all the Flask modules and ran my main.py. Then I recreated the database and it finally worked. No idea what caused the problem since I didn't edit anything, but it's fine now. Also, last night the Class.query_all() command didn't work in the terminal but now it does and I'll be able to see my tables when I start adding them, so everything ended up working out.

1337toothbrush posted...
I started learning the basics of programming while screwing around with RPG Maker 2000 as a kid, but that was a purely point and click interface at the time. Then I picked more up through high school computer science classes and later on in university where I earned my degree in computer science (though for practical programming I learned it mostly through side projects in my spare time). I work as a software engineer, so I keep up to date with stuff.
What's your daily schedule like? I don't have a CS degree and I'm just self-teaching. I have no idea what I want to do with programming yet but I live in the Bay Area so I have a lot of options. I was thinking of continuing my teaching, try getting an entry level position somewhere and then go back to school for a new degree at the same time.

---
FAM FOREVER.
... Copied to Clipboard!
1337toothbrush
08/30/21 9:10:38 AM
#195:


SomeLikeItHoth posted...
What's your daily schedule like? I don't have a CS degree and I'm just self-teaching. I have no idea what I want to do with programming yet but I live in the Bay Area so I have a lot of options. I was thinking of continuing my teaching, try getting an entry level position somewhere and then go back to school for a new degree at the same time.
Daily schedule at work or in general? My work hours typically span from 7am to 3pm, but that's been moving around a bit with working from home. During those work hours it's not really fixed because it depends on what projects I'm working on and what needs to be done in those projects.

---
... Copied to Clipboard!
SpiritSephiroth
08/30/21 8:13:45 PM
#196:


Okay! I think something finally clicked. I just threw the whole code into the while loop and it works. And because I'm using classes, its not as messed up as it would have been if I didn't learn it while trying to figure this mess out!

In other words, my code is in the clear for now. I can finally continue with this madness and expand on it!



My code so far. Im actually glad I had trouble here, because it forced me to learn Classes more thoroughly and now I have a better understanding of it overall!

Edit: Just realized, I'll need to move the Imps code within the While loop as well so it can roll its strength stats randomly like the player code. But other than that, I can continue finally. Also ignore that "character stats" variable. I forgot to remove it.

---
... Copied to Clipboard!
VigorouslySwish
08/30/21 8:18:46 PM
#197:


Is it worth it to learn python in hopes of getting a low level job with no degree

---
i'm just some guy yellin' about apple sauce
... Copied to Clipboard!
SpiritSephiroth
08/30/21 8:20:20 PM
#198:


The more I look at my code, the more I see things I need to fix. So I'll get on that first thing tomorrow.

---
... Copied to Clipboard!
Questionmarktarius
08/30/21 8:27:11 PM
#199:


SpiritSephiroth posted...
Edit: Just realized, I'll need to move the Imps code within the While loop as well so it can roll its strength stats randomly like the player code.
You've almost realized that Player and Imp are functionally more or less the same thing. Your next step here is class inheritance.
... Copied to Clipboard!
SpiritSephiroth
08/30/21 8:30:02 PM
#200:


Questionmarktarius posted...
You've almost realized that Player and Imp are functionally more or less the same thing. Your next step here is class inheritance.

That sounds interesting, need to look this up tomorrow thanks!

Also I was going to create a class for the Imp too, but seeing as it was only a few lines of code, I didn't go through the hassle. But for practice I really should do it.

---
... Copied to Clipboard!
Topic List
Page List: 1, 2, 3, 4, 5, 6, 7, 8 ... 10