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
  Simple encoding code ebolisa 3 454 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 830 Feb-21-2022, 10:52 AM
Last Post: Gribouillis
  Pyspark - my code works but I want to make it better Kevin 1 1,003 Dec-01-2021, 05:04 AM
Last Post: Kevin
Question email code works in 2.7 but not in 3 micksulley 3 1,356 Nov-04-2021, 09:44 PM
Last Post: micksulley
  Simple code question about lambda and tuples JasPyt 7 1,780 Oct-04-2021, 05:18 PM
Last Post: snippsat
Sad SyntaxError: from simple python example file from mind-monitor code (muse 2) warmcupoftea 4 1,457 Jul-16-2021, 02:51 PM
Last Post: warmcupoftea
  Plotting sum of data files using simple code Laplace12 3 1,953 Jun-16-2021, 02:06 PM
Last Post: BashBedlam
  HackerRank Problem: Code works on VS Code but not on the HackerRank site Pnerd 3 1,640 Feb-28-2021, 07:12 PM
Last Post: Pnerd
Question Google Foobar- Code works in my IDE but not in foobar. Static method? pr3ttykitty 4 3,188 Feb-24-2021, 05:03 PM
Last Post: nilamo
  Help with isinstance command (very simple code) Laplace12 2 1,337 Jul-30-2020, 05:26 AM
Last Post: Laplace12

Forum Jump:

User Panel Messages

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