Python Forum
Beginner problem in python script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beginner problem in python script
#1
Hi there,
I have followed a tutorial, but i don't manage to solve this error :
Error:
"cedmo@cedmo-HP-EliteBook-8770w:~$ ./DragonRdm.py File "./DragonRdm.py", line 31 if nombre == random.randint(1,10): ^ SyntaxError: invalid syntax"
My script (i'm using Vim) is written like this :
#!/usr/bin/env python # -*-coding:Latin-1 -* import random print("Tu te trouves dans une pièce obscure d'un mystérieux chateau.") print("Tu dois choisir entre quatre portes.") choixJoueur = input("Choisis 1, 2, 3 ou 4...") if choixJoueur == "1": print("Tu as trouvé un trésor. Tu es riche !") print("BRAVO, TU AS GAGNE !") elif choixJoueur == "2": print("La porte s'ouvre et un ogre affamé te donne un coup de massue.") print("GAME OVER, TU AS PERDU !") elif choixJoueur == "3": print("Il y a un dragon endormi dans cette pièce.") print("Tu peux soit :") print("1) Essayer de voler l'or du dragon.") print("2) Essayer d'échapper au dragon.") choixDragon = input("Entre 1 ou 2...") if choixDragon == "1": print("Le dragon se réveille et te mange. Il te trouve délicieux.") print("GAME OVER, TU AS PERDU !") elif choixDragon == "2": print("Tu échappes au dragon, tu sors du château et tu revois la lumière du jour.") print("BRAVO, TU AS GAGNE.") else: print("Désolé, tu n'as pas entré 1 ou 2 !") elif choixJoueur == "4": print("Tu entres dans une pièce où se trouve un sphinx.") print("Il te demande de deviner à quel nombre il pense, entre 1 et 10.") nombre = int(input("Quel chiffre choisis-tu ?") if nombre == random.randint(1,10): print("Déçu, le sphinx émet un sifflement. Tu as deviné juste.") print("Il doit te laisser partir.") print("BRAVO, TU AS GAGNE !") else: print("Le sphinx te dit que tu n'as pas deviné le bon chiffre.") print("Tu es désormais son prisonnier à jamais.") print("GAME OVER, TU AS PERDU !") else: print("Désolé, tu n'as pas entré 1, 2, 3 ou 4 !") print("Lance à nouveau le jeu pour réessayer.")
I don't understand where the syntax of the 31st line is wrong.
Thanks to the people who will help me :)
Reply
#2
It is because the previous line is missing a close bracket
 nombre = int(input("Quel chiffre choisis-tu ?")# ) Missing from here if nombre == random.randint(1,10):
Reply
#3
There is a missing closing ) parenthese at line 30.

SyntaxError is always a very simple error. Make a list of your mistakes when
you meet a SyntaxError, then use this list a a check list for the next time.
Reply
#4
It works, thx :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Script problem - Illegal access to removed OSM object MarcPolo72 0 1,737 Jun-23-2024, 04:26 PM
Last Post: MarcPolo72
  Python beginner that needs an expression added to existing script markham 1 1,907 Sep-04-2023, 05:24 AM
Last Post: Pedroski55
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 10,066 Jun-29-2023, 11:57 AM
Last Post: gologica
  Script stop work after 3 actioins - PLEASE WHERE IS THE PROBLEM? rondon442 0 2,377 Sep-27-2021, 05:40 PM
Last Post: rondon442
  Problem executing a script on a remote host tester_V 3 4,610 Sep-26-2021, 04:25 AM
Last Post: tester_V
  problem with sphinx and file directory in script kiyoshi7 0 3,345 Mar-11-2021, 03:52 PM
Last Post: kiyoshi7
  small beginner problem FelixReiter 2 2,932 Nov-17-2020, 03:26 PM
Last Post: FelixReiter
  Beginner having Syntax Error problem RyanHo 3 4,000 Sep-10-2020, 08:33 AM
Last Post: cnull
  problem about slope in python script for bitcoin trading fisher_garry 1 3,804 Sep-02-2020, 01:39 PM
Last Post: fisher_garry
  Beginner, my recursion returns None, and related problem zpacemanzpiff 2 3,088 Jul-02-2020, 04:25 AM
Last Post: zpacemanzpiff

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.