Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在更换字符的同时更换Scre?_Python 3.x - Fatal编程技术网

Python 3.x 如何在更换字符的同时更换Scre?

Python 3.x 如何在更换字符的同时更换Scre?,python-3.x,Python 3.x,我想写一个游戏程序,生成一个随机数N,由8个字符组成,从9开始。然后用户也会写一个数字a,从9开始,由8个字符组成,他有8次这样做的机会,他以分数=100开始,因此如果用户编号与N相同,程序将以“做得好”结束,如果不是,程序将以a和N结束,因此,如果a中的一个字符在N中的正确位置,他将停留在相同的位置,如果该字符正确但不在正确的位置,他将被“”替换,如果该字符不在N中,他将被“-”替换。此外,用户将以100分开始。每一个“分数”将减少1分,每一个“-”将减少2分。我试过这个密码: from ra

我想写一个游戏程序,生成一个随机数N,由8个字符组成,从9开始。然后用户也会写一个数字a,从9开始,由8个字符组成,他有8次这样做的机会,他以分数=100开始,因此如果用户编号与N相同,程序将以“做得好”结束,如果不是,程序将以a和N结束,因此,如果a中的一个字符在N中的正确位置,他将停留在相同的位置,如果该字符正确但不在正确的位置,他将被“”替换,如果该字符不在N中,他将被“-”替换。此外,用户将以100分开始。每一个“分数”将减少1分,每一个“-”将减少2分。我试过这个密码:

from random import*
N= "9"+str(randint(1000000,9999999))
G=str(N)

Score=100        
C = 0
Valide = False

while Valide == False and C<=8:                
    A=input("complete number of 8 characters"+'\t'+"9")
    T=str(A)
    if A.isdigit() == True:
        print("")
    while A.isdigit() == False:
        A=input("Terminer le nombre de 8 chiffres"+'\t'+"9")

    while len(A)!=7:
        A=input("complete number of 8 characters"+'\t'+"9")

    if "9"+A==N:
        Valide = True
        print("you got it!")
        print("Score:",Score)
        exit()

    for k in G:
        for v in T:

            if v == k:
                S=v
            elif v in k:
                S=T.replace(str(T.index(v)),"*")
            else:
                S=T.replace(str(T.index(v)),"-")

        if "*" in S:
            Score -=1
        if "-" in S:
            Score -=2

    print ('9'+ S)

    print (Score)
    C += 1

if A==N :
    print("Bravo")
else:
    print("Game Over")
    print("You've reached the maximum number of guesses.")
    print("Score:",Score)
    exit()
来自随机导入的
*
N=“9”+str(randint(100000999999))
G=str(N)
分数=100
C=0
Valide=False
而Valide==False和C