因此,我建议他们作为初学者使用these projects。我坚持第三个项目,我也试图完成子任务:
def PythagTripCheck():
sidesCount=0
smallSideDone=False
mediumSideDone=False
largeSideDone=False
while sidesCount<3:
whatSide=input("What side would you like to enter first? 'Small', 'Medium' or 'Large'?")
if whatSide=="Small" or "small" or "S" or "s" and smallSideDone==False:
smallSide=input("Enter the length of the small side:")
if smallSide.isdigit() == False:
print("The small side contains a character which is not a number, your numbers have been reset, try again")
PythagTripCheck()
else:
sidesCount=sidesCount+1
smallSideDone=True
elif whatSide=="Medium" or "medium" or "M" or "m" and mediumSideDone==False:
mediumSide=input("Enter the length of the medium side:")
if mediumSide.isdigit() == False:
print("The medium side contains a character which is not a number, your numbers have been reset, try again")
PythagTripCheck()
else:
sidesCount=sidesCount+1
mediumSideDone=True
elif whatSide=="Large" or "large" or "L" or "l"and largeSideDone==False:
largeSide=input("Enter the length of the large side")
if largeSide.isdigit() == False:
print("The large side contains a character which is not a number, your numbers have been reset, try again")
PythagTripCheck()
else:
sidesCount=sidesCount+1
largeSideDone=True
else:
print("Please try again")
PythagTripCheck()
无论如何,代码都会运行小方。 whatSide会从初始值更改为不同的值,并且当尝试第二次(不同)尝试时,当对应的一方执行时,[side] SideDone会更改为True。但是,
if whatSide=="Small" or "small" or "S" or "s" and smallSideDone==False:
smallSide=input("Enter the length of the small side:")
if smallSide.isdigit() == False:
print("The small side contains a character which is not a number, your numbers have been reset, try again")
PythagTripCheck()
else:
sidesCount=sidesCount+1
smallSideDone=True
总是经历,我不明白为什么。我试过http://www.pythontutor.com/,它甚至说whatSide的值不等于小方的任何参数。
我做错了什么?