我不明白为什么在我做的菜单中选择了一个不同的选项之后,我不能在代码的后面部分打印列表的内容。我怎样才能把清单的内容进行下去
这是一个学校评估,我们应该创建一个python代码,允许用户从菜单中选择创建一个数字根列表>;我尝试将包含所有其他列表的列表附加到不同的位置
def checkAnswer():
global userInput
global overallList
if userInput < "1" or userInput > "3":
print("That isn't a valid option!")
runAll()
elif userInput >= "1" and userInput <= "3":
if userInput == "1":
print("You have chosen to create a new spirolateral.")
spirolNumber = input("What number would you like to add as a spirolateral?")
try:
intValue = int(spirolNumber)
digitValue = digital_root(intValue)
print("Okay, adding", intValue, "as a spirolateral.")
initialValue = digitValue # Creates a value that matches the digitValue so that it isn't lost.
rootList = [] # Creates an empty list to add the numbers to.
loopingNumber = False # SO that I can create a while loop later to determine when the number repeats.
while loopingNumber == False: # Makes sure the loop only runs while this is false.
if digitValue in rootList: # Checks if digitValue is a value in the rootList list.
loopingNumber = True # Changes this to true so that it stops the while loop from running.
print(rootList)
else:
loopingNumber = False # Ensures that the value stays false.
rootList.append(digitValue)
digitValue += initialValue
digitValue = digital_root(digitValue)
overallList.append(rootList)
print(overallList)
except ValueError:
print("Please use a whole number!")
elif userInput == "2":
print("You have chosen to edit an existing spirolateral.")
totalLists = len(overallList)
**editList = input(print("Which spirolateral would you like to edit? You can choose from", overallList, "Please enter a number from 0 to", totalLists)) # From here overallList doesn't print anything that was added in the area if the user would have initially entered 1.**
spirolNumber = input("What number would you like to change this digital root to instead?")
try:
int(editList)
overallList.remove(editList)
except ValueError:
print("Please enter a valid option!")
try:
intValue = int(spirolNumber)
digitValue = digital_root(intValue)
print("Okay, adding", intValue, "as a spirolateral.")
initialValue = digitValue # Creates a value that matches the digitValue so that it isn't lost.
rootList = [] # Creates an empty list to add the numbers to.
loopingNumber = False # SO that I can create a while loop later to determine when the number repeats.
while loopingNumber == False: # Makes sure the loop only runs while this is false.
if digitValue in rootList: # Checks if digitValue is a value in the rootList list.
loopingNumber = True # Changes this to true so that it stops the while loop from running.
print(rootList)
else:
loopingNumber = False # Ensures that the value stays false.
rootList.append(digitValue)
digitValue += initialValue
digitValue = digital_root(digitValue)
overallList.append(rootList)
print(overallList)
except ValueError:
print("Please enter a valid option!")
我希望本节开头的输出可以打印出来 “您要编辑哪个螺旋体?”?您可以从[[list1 contents]、[list2 contents]、[list3 contents]、[etc]]中选择请输入0到3之间的数字 但结果却是 “您要编辑哪个螺旋体?”?您可以从[]中选择请输入一个从0到0的数字“
目前没有回答
相关问题 更多 >
编程相关推荐