Python Forum
Please help I'm a beginner
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please help I'm a beginner
#1
Sorry for possible language mistakes, I'm french
I started programmation for a year but i don't remember anything about it, i'm a total beginner an i want to learn but i don't understand what's wrong with my program, can you help me please.
(I tried to share my project but i'm not sure it works)
metulburr write Sep-05-2021, 12:50 PM:
Please post your code on the forums in code tags so everyone does not have to download the file
https://python-forum.io/misc.php?action=help&hid=25

Attached Files

.py   Premier jeux vidéo en python.py (Size: 11.38 KB / Downloads: 302)
Reply
#2
Learn classes now. Start with them as simple containers. They will make your life so much easier. Classes are reference. So you never need to use global.
Examples
class Character:
    def __init__(self, max_life, attack, defense, shield):
        self.max_life = max_life
        self.life = max_life
        self.attack = attack
        self.defense = defense
        self.shield = shield
        self.alive = True

player = Character(50, 3, 3, 3)
for k, v in vars(player).items():
    print(k, v)
class Weapon:
    def __init__(self, name, attack):
        self.name = name
        self.attack = attack

    # Represent class as string instead object memory.
    def __repr__(self):
        return str(vars(self)) + '\n'

class Weapons:
    def __init__(self):
        self.dagger = Weapon('Daque', 3)
        self.sword = Weapon('Epee', 6)
        self.bow = Weapon('Arc', 5)

weapons = Weapons()

def main():
    print(vars(weapons))
    print(weapons.sword)
    weapons.sword.attack += 1
    print(weapons.sword)

main()
99 percent of computer problems exists between chair and keyboard.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020