Python Forum

Full Version: 2 lines causing code failure
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I need your help,
I'm a beginner in python and i'm facing a problem with my code . It fails once I add two lines , even if it seems to be correct
herunde both codes :

the successful code
# -*-coding:Latin-1 -*
import 	os
from 	donnees 	import *
from 	fonctions 	import *

ScorePlayer = GetPlayerScore(MyScore)
print("le score est {} ".format(ScorePlayer))
SplitWord		= list()
CryptedWord		= list()
ClairWord       = GetHazardWord()
SplitWord		= list(ClairWord)
print(SplitWord)
for word in SplitWord:
	CryptedWord.append('*')
print("Le mots a trouve est===================== {} =====================".format(CryptedWord))
while Tries < MaxTries:
	CarFound = '0'
	character = input("Merci de saisir un caractere ")
	for elmnt in SplitWord:
		if elmnt==character:
			CarFound = '1'
			break
	Tries = Tries + 1
os.system("pause")
non successful code
# -*-coding:Latin-1 -*
import 	os
from 	donnees 	import *
from 	fonctions 	import *

ScorePlayer = GetPlayerScore(MyScore)
print("le score est {} ".format(ScorePlayer))
SplitWord		= list()
CryptedWord		= list()
ClairWord       = GetHazardWord()
SplitWord		= list(ClairWord)
print(SplitWord)
for word in SplitWord:
	CryptedWord.append('*')
print("Le mots a trouve est===================== {} =====================".format(CryptedWord))
while Tries < MaxTries:
	CarFound = '0'
	character = input("Merci de saisir un caractere ")
	for elmnt in SplitWord:
		if elmnt==character:
			CarFound = '1'
			break
	if CarFound =='1':
		print("OK")
	Tries = Tries + 1
os.system("pause")
Thank you in advance
What is the expected behavior? How is the script failing?
As @stullis said - show us the full traceback if you get any errors and elaborate on what failing actually means in this case
Please, read What to include in a post
I'm sorry but no error displayed. I've just double clicked on the ".py" file and the console exit . even if I tried to put try except block but nothing was catched .

this morning I rollbacked to the old version (script 1 shared above) and nothing was working . so I copied the instructions one by one again except the block from 16 to 23 (this block is no more accpeted )

I can share all my code :
file pendu.py
# -*-coding:Latin-1 -*
import 	os
import traceback
from donnees 	import *
from fonctions 	import *
ScorePlayer = GetPlayerScore(MyScore)
print("le score est {} ".format(ScorePlayer))
SplitWord		= list()
CryptedWord		= list()
ClairWord       = GetHazardWord()
SplitWord		= list(ClairWord)
print(SplitWord)
for word in SplitWord:
	CryptedWord.append('*')
print("Le mots a trouve est===================== {} =====================".format(CryptedWord))
while Tries < MaxTries:
	CarFound = '0'
	character = input("Merci de saisir un caractere ")
	for elmnt in SplitWord:
		if elmnt==character:
			CarFound = '1'
			break
	Tries = Tries + 1

os.system("pause")
file fonctions.py
# -*-coding:Latin-1 -*
import os
from donnees import *
import random
import pickle

def GetHazardWord():
	seq=random.choice(ListeMots)
	return seq
def GetPlayerScore(PlayerScore):
	global MyScore	#pour s'assurer que la portée de variable MyScore sera aussi hors la fonction GetPlayerScore
	PlayerName = input("Merci de saisir votre nom ")
	with open('score','rb') as DBFile:
		DBScore = pickle.Unpickler(DBFile)
		PlayersScore = DBScore.load()
	for cle,value in PlayersScore.items():
		if PlayerName == cle:
			MyScore = value
			print("PlayerScore INSIDE ",MyScore)
			return PlayersScore
	with open('score','wb') as DBFile:
		DBScore = pickle.Pickler(DBFile)
		PlayerScore = DBScore.dump({PlayerName:PlayerScore})
	return {PlayerName:MyScore}
if __name__=="__main__":
	print("la sequence du mot choisi est",GetHazardWord())
	print("Score de {} ".format(GetPlayerScore(MyScore)))
	os.system("pause")
file donnees.py
# -*-coding:Latin-1 -*
import os
ScoreFile 	= "Score"
MaxTries 	= 8
Tries		= 0
MyScore		= 0
ListeMots 	= [
				"smail",
				"azzedine",
				"yassine",
				"youssef",
				"omar",
				"amina",
				"nora",
				"maryam",
				"meriem",
		]
if __name__=="__main__":
	print("La listes des mots {}".format(ListeMots))
	os.system("pause")
don't click on the file. Open the cmd.exe (Command Prompt) and run file from there. This way you the command prompt window will not close and you will see the full traceback.
I don't see any problem with the two lines you add (based on the code in the original post)
Hi Buran,

Exactely you are right . by chance I went to set my window environement in order to run the project from the cmd . and could get this error
Error:
File "pendu.py", line 1 SyntaxError: encoding problem: iso-8859-1
I fixed the issue by removing the first line . even if I could not understand the random behaviour of compiler

Appreciate you collaboration