Python Forum
My simple code don't works !!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My simple code don't works !!
#1
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]
buran write Sep-06-2021, 10:29 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
You have a bad character in line 78, which you did not include.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with simple code JacobSkinner 1 318 Mar-18-2024, 08:08 PM
Last Post: deanhystad
  My code works on Jupyter Lab/Notebook, but NOT on Visual Code Editor jst 4 992 Nov-15-2023, 06:56 PM
Last Post: jst
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 480 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Code works but doesn't give the right results colin_dent 2 710 Jun-22-2023, 06:04 PM
Last Post: jefsummers
  Code used to work 100%, now sometimes works! muzicman0 5 1,442 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  help me simple code result min and max number abrahimusmaximus 2 904 Nov-12-2022, 07:52 AM
Last Post: buran
  Simple encoding code ebolisa 3 1,441 Jun-18-2022, 10:59 AM
Last Post: deanhystad
  How would you (as an python expert) make this code more efficient/simple coder_sw99 3 1,799 Feb-21-2022, 10:52 AM
Last Post: Gribouillis
  Pyspark - my code works but I want to make it better Kevin 1 1,779 Dec-01-2021, 05:04 AM
Last Post: Kevin
Question email code works in 2.7 but not in 3 micksulley 3 2,580 Nov-04-2021, 09:44 PM
Last Post: micksulley

Forum Jump:

User Panel Messages

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