【发布时间】:2022-06-14 20:47:44
【问题描述】:
请帮助我如何访问位于函数中的变量 lastPattern 并将其访问到其他函数。这是我的代码:
def easyLevel():
global score
n = 2
while n <= 6:
pattern = random.choice(string.ascii_lowercase)
for i in range(n-1):
pattern = pattern + " " + random.choice(string.ascii_lowercase)
print("\nThe pattern is: ")
print(pattern + "\n")
countDown(5)
easyAns = str(input("What was the pattern?: "))
if easyAns == pattern:
n = n + 1
print("That's correct!")
score = score + 5
allPatterns.append(pattern)
else:
print("\nSorry, that's incorrect.")
print("Your score is: " + str(score))
break
lastPattern = allPatterns[-1]
with open('Leaderboard.csv', 'a') as file:
csv_writer = csv.writer(file)
csv_writer.writerow([name, score, lastPattern])
【问题讨论】:
-
我认为您的代码格式不正确。请仔细检查。