猜单词的那部分代码被运行了两遍,什么回事啊

import random
def judge(n):
scard=0
n-=1
words=['easy','python','techer','giao','pipe']
print("欢迎参加猜单词游戏!\n请把乱序后的字母组成一个单词\n")
for i in range(5):
n-=1
print("剩余猜测次数:",n)
word=random.choice(words)
answer=word
jumble=""
while word:
position=random.randrange(len(word))
jumble+=word[position]
word=word[:position]+word[(position+1):]
print("乱序后的单词:",jumble)
guess=input("\n请输入您猜测的结果:")
if guess !=answer:
scard+=0
print("\n对不起,猜错了!")
else:
scard+=2
print("\n恭喜您,猜对了!")
return scard
def scard(scard):
if scard==10 :
print("成绩等级为A")
elif scard>=8 and scard<10:
print("成绩等级为B")
elif scard>=6 and scard<8:
print("成绩等级为C")
elif scard>=4 and scard<6:
print("成绩等级为D")
elif scard>=2 and scard<4:
print("成绩等级为E")
elif scard>=0 and scard<2:
print("成绩等级为F")
print(judge(7))
scard(judge(7))

应该是因为最后两行代码那里,print(judge(7))这里执行了一次猜单词函数judge(),然后scard(judge(7))这里又执行了 一次猜单词函数judege()的原因,所以猜单词部分运行了两次,去掉一个即可,修改如下:

import random

def judge(n):
    scard=0
    n-=1
    words=['easy','python','techer','giao','pipe']
    print("欢迎参加猜单词游戏!\n请把乱序后的字母组成一个单词\n")
    
    for i in range(5):
        n-=1
        print("剩余猜测次数:",n)
        word=random.choice(words)
        answer=word
        jumble=""
        while word:
            position=random.randrange(len(word))
            jumble+=word[position]
            word=word[:position]+word[(position+1):]
        print("乱序后的单词:",jumble)
        guess=input("\n请输入您猜测的结果:")
        if guess !=answer:
            scard+=0
            print("\n对不起,猜错了!")
        else:
            scard+=2
            print("\n恭喜您,猜对了!")
    return scard

def scard(scard):
    if scard==10 :
        print("成绩等级为A")
    elif scard>=8 and scard<10:
        print("成绩等级为B")
    elif scard>=6 and scard<8:
        print("成绩等级为C")
    elif scard>=4 and scard<6:
        print("成绩等级为D")
    elif scard>=2 and scard<4:
        print("成绩等级为E")
    elif scard>=0 and scard<2:
        print("成绩等级为F")
    #print(judge(7))

scard(judge(7))


img