python - 最大递归,如何修复
问题描述
我的代码停止工作。它在调用 Python 对象时输出超出的最大递归深度 这是我的代码:
# First We import time for waiting, random for selecting the 3 numbers, and the 3 globals for use of other functions
import time
import random
import sys
global ca2
global ca1
global ca3
global guesses
global correctNumbers
global correctOrder
guesses = 0
def lose():
print("You have ", correctNumbers, "Numbers Correct")
print("And", correctOrder, "Numbers That are correct in order.")
startLevel1()
def win():
print("Congratulations!")
print("It took you", guesses, "guesses to Win.")
q2 = input()
if q2 == "yes":
startGame()
def input():
# entering numbers
correctNumbers = 0
ca1 = 0
ca2 = 0
ca3 = 0
numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
ca1 = random.choice(numbers)
ca2 = random.choice(numbers)
ca3 = random.choice(numbers)
ifa = [ca1, ca2, ca3]
correctOrder = 0
input1 = input()
input2 = input()
input3 = input()
if input1 == ca1: #here we are testinf for input1 of all 3 numbers.
print("The First Number Is 100% Correct. Number and Order.")
correctNumbers += 1
correctOrder += 1
if input1 == ifa:
correctNumbers += 1
if input2 == ca2: #over here we are doing the same thing but for 2
print("The Second number Is 100% Correct. Number and Order.")
correctOrder += 1
correctNumbers += 1
if input2 == ifa:
correctNumbers += 1
if input3 == ca3: #same here, but for 3
print("The Third number Is 100% Correct. Number and Order.")
correctOrder += 1
correctNumbers += 1
if input3 == ifa:
correctNumbers += 1
if correctNumbers == 3:
win()
else:
lose()
guesses += 1
def startLevel1():
#chooses the numbers
wait1sec()
numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
ca1 = random.choice(numbers)
ca2 = random.choice(numbers)
ca3 = random.choice(numbers)
input()
#The game starts here
def startGame():
guesses = 0
print("Welecome To Mastermind!")
print("How To Play:")
wait1sec()
print("1. The Computer will select 3 numbers from 1 to 10, you must guess all 3 numbers in the right order.")
wait1sec()
print("2. Each time you guess, the computer will tell you how much numbers did you guess right, and tell you if those numbers were in the correct order.")
wait1sec()
print("3.There is no limit to how much guesses you can use.")
wait1sec()
print("You win by guessing all the correct numbers in the right order")
startLevel1()
def wait1sec():
time.sleep(1)
startGame()
我正在制作一款名为 mastermind 的游戏。我尝试使用dict
s 但它们不起作用,任何人都可以帮助我,我只是一个初学者,谢谢。我也在使用 pycharm 和 python 3.0。我认为这是因为所有的如果?我真的不知道
解决方案
推荐阅读
- css - 如何在隐藏溢出的情况下将图像背景拉伸到外侧?
- google-apps-script - 如何将 Google Meet 和 Google Meet 直播网址导出到 Google 表格?
- android-studio - 同步 Gradle Android Studio 项目时出错
- python - 带参数的 Python 回调
- xmpp - 从对话客户端应用程序登录 ejabberd 服务器上的注册用户不起作用
- azure-devops - 如何仅在合并的拉取请求上触发任务?
- python - 如何修复此 AttributeError:“NoneType”对象没有属性“文本”?
- database - 如何优化 InfluxQL 查询以加载 Influxdb 1.8 上的所有内核
- cypress - 为什么我不能通过返回 false 来打破柏树中的每个循环?
- java - 日志行需要 10 毫秒