Python - Function and Variable Problem

Asked

Viewed 91 times

0

Well, I’m doing an old game project in Python, but in VS Code is giving an error in the print of an unused function and variable.

First the function error, I’m using the library Colorama which, I can use colors. So in the first lines of the code I’ve put like this:

import os 
import random
from colorama import Fore, Back, Style

Being so, I went to make the first variables with the functions:

jogarNovamente="s"
jogadas=0
quemJoga=2 # 1=CPU - 2=Jogador
maxJogadas=9
vit="n"
velha=[
    [" "," "," "],
    [" "," "," "],
    [" "," "," "]

]

def tela():
    global velha
    global jogadas
    os.system("cls")
    print("    0   1   2")
    print("0:  " + velha[0][0] + " | " +velha[0][1] + " | " + velha[0][2])
    print("   -----------")
    print("1:  " + velha[1][0] + " | " +velha[1][1] + " | " + velha[1][2])
    print("   -----------")
    print("2:  " + velha[2][0] + " | " +velha[2][1] + " | " + velha[2][2])
    print("Jogadas: " + Fore.GREEN + str(jogadas) + Fore.RESET)

"fore" I used it on behalf of Coloram and the .RESET to end there.

And when I go to the terminal to run, it appears as follows:

inserir a descrição da imagem aqui

Instead of trimming "Thrown=0" in green, these numbers appear. I went to the PIP to see if the Color Chart was working, and it is.

In the same code, is giving errors of variables, as for example in the player function.

def jogadorJoga():
global jogadas
global quemJoga
global maxJogadas
if quemJoga==2 and jogadas<maxJogadas:
    try:
        l=int(input("Linha..: "))
        c=int(input("Coluna.: "))
        while velha[1][c]!= " ":
            l=int(input("Linha..: "))
            c=int(input("Coluna.: "))
        velha[1][c]="X"
        quemJoga=1
        jogadas+=1
    except:
        print("Jogada invalida")
        os.system("pause")
        #vit="n"

In the case of the variable l, when I go to the terminal gives the unused variable error. And the amazing thing is that the variable c is not giving problem in the terminal, only the l.

l= line c= column

I searched about and it seems that it has to do with Pylint that does not recognize variables with less than 3 characters, but I went to do even with more than 3 and the terminal is giving the same unused variable error.

I know it’s a big question, but who knows how to answer I’m grateful. As said at the beginning, I use the IDE Visual Studio Code.

  • 3

    About Coloram output, the terminal you are using to run the script should not have support for the characters that define the colors of the text. Over the unused variable, does not give the same message for the variable c because it is using it, already the l no, since in the while you put the number 1 instead of the variable.

  • Regarding the terminal, I searched and I saw that it has how to configure... I will see if there is some type of configuration to appear these colors. And well, I hadn’t really seen that instead of I was number one, a very simple mistake that I wasn’t seeing. I put it in and it’s working again, thank you very much.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.