Python Forum
2 lines causing code failure
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
2 lines causing code failure
#1
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
Reply
#2
What is the expected behavior? How is the script failing?
Reply
#3
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
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")
Reply
#5
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)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Failure to run source command middlestudent 2 689 Sep-22-2023, 01:21 PM
Last Post: buran
  Dickey Fuller failure Led_Zeppelin 4 2,606 Sep-15-2022, 09:07 PM
Last Post: Led_Zeppelin
  Regular Expression search to comment lines of code Gman2233 5 1,658 Sep-08-2022, 06:57 AM
Last Post: ndc85430
  I want to simplify this python code into fewer lines, it's about string mandaxyz 5 2,114 Jan-15-2022, 01:28 PM
Last Post: mandaxyz
  Assert failure jtcostel 1 1,635 Sep-03-2021, 05:28 PM
Last Post: buran
  string.format() suddenly causing errors with google drive API zwitrader 0 1,753 Jun-28-2021, 11:38 PM
Last Post: zwitrader
  python seems to be skipping lines of code alansandbucket 1 4,144 Jun-22-2021, 01:18 AM
Last Post: Larz60+
  Running a few lines of code as soon as my timer ends nethatar 3 2,396 Feb-26-2021, 01:02 PM
Last Post: jefsummers
  Assistance with running a few lines of code at an EXACT time nethatar 5 3,233 Feb-24-2021, 10:43 PM
Last Post: nilamo
  Making new lines of code AvioxyYT 1 1,793 Jan-22-2021, 07:02 PM
Last Post: buran

Forum Jump:

User Panel Messages

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