Python Forum
My simple code don't works !! - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: My simple code don't works !! (/thread-34840.html)



My simple code don't works !! - Nabi666 - Sep-06-2021

Sorry for possible language mistakes, i'm french

I did a simple video game but my function fight don't works, i don't know why, can you help me ?

Enemies = [{Name:'Le squelette', ELife: 30, Atk: 4, Def: 3},
            {Name:'Le gobelin', ELife: 40, Atk: 5, Def: 4},
             {Name: 'La liche', ELife: 60, Atk: 6, Def: 4}]

Enemy = Enemies(randint(0, len(Enemies)-1))

    
def fight(Enemy): #Enemy est un élément de la liste Enemies
    global Life, Alive
    while Life > 0 and Enemy[ELife] > 0:
        choice = int (input('Voulez-vous attaquer (1) ou defendre (2) ?'))
        EnemyChoice = randint(1, 2)
        if choice == 1 and EnemyChoice == 1:
            print('Vous attaquez !', Enemy[Name],'perd', (Attack + Weapon) - Enemy [Def], 'pv.')
            Enemy[ELife] -= (Attack + Weapon) - Enemy [Def]
            if Enemy[ELife] > 0:
                print(Enemy[Name], 'n\'a plus que', Enemy[ELife], 'pv, courage !')
            if Enemy[ELife] <= 0:
                continue 
            print(Enemy[Name], 'attaque! Vous perdez', Enemy[Atk] - Defense, ('pv.'))
            Life -= Enemy[Atk] - Defense
            if Life < 0:
                Life = 0
            print('Il vous reste', Life, 'pv.')
        elif choice == 1 and EnemyChoice == 2:
            print('Vous attaquez... mais', Enemy[Name].lower(), 'defend, il perd', (Attack + Weapon) - Enemy [Def] * 2,'pv.')
            Enemy[ELife] -= (Attack + Weapon) - Enemy [Def] * 2
            if Enemy[ELife] > 0:
                print(Enemy[Name], 'n\'a plus que', Enemy[ELife], 'pv, courage !')
        elif choice == 2 and EnemyChoice == 1:
            print(Enemy[Name], 'attaque mais vous defendez, vous perdez', Enemy[Atk] - (Defense + Shield), 'pv')
            Life -= Enemy[Atk] - (Defense + Shield)
            if Life < 0:
                Life = 0
            print('Il vous reste', Life, 'pv.')
        elif choice == 2 and EnemyChoice == 2:
            print('Vous et le', Enemy, 'êtes en train de defendre, la tension est palpable...')
        else:
            print('Votre choix n\'est pas valide. Tapez 1 ou 2')
        if Enemy[ELife] <= 5 and Enemy[ELife] >= 4:
            print('Vous y êtes presque !')
        elif Enemy[ELife] <= 3 and Enemy[ELife] >= 1:
            print('Encore un petit effort')
    if Enemy[ELife] <= 0:
        print('Félicitation ! Vous avez battu', Enemy[Name].lower() + '.')
    else:
        Alive = False

And that's the error message :
Error:
File "/Users/Nathan/Documents/Programmation/Premier jeux vidéo en python.py", line 78 SyntaxError: Non-ASCII character '\xc3' in file /Users/Nathan/Documents/Programmation/Premier jeux vidéo en python.py on line 78, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details [Finished in 0.2s with exit code 1] [shell_cmd: python -u "/Users/Nathan/Documents/Programmation/Premier jeux vidéo en python.py"] [dir: /Users/Nathan/Documents/Programmation] [path: /Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands]



RE: My simple code don't works !! - jefsummers - Sep-06-2021

You have a bad character in line 78, which you did not include.