我是计算机编程的新手,目前正在 PyCharm Community 中编写一个程序,当给出我学校学生的名字时,它会打印出从学校到该学生家的路线。
一切都进行得很顺利,昨晚我得到了它的基础。今天我打开我的电脑,出于某种原因,我的程序拒绝运行我的“if”/“elif”语句,并且只会运行 else 语句,即使它的值满足“if”/“elif”语句。
我试过重写程序,多次重启 PyCharm,确保我的空格和制表符一致,并确保我的变量都可以相互通信。我已经在这里和其他网站上搜索了一段时间,但我只是看不出为什么我的代码昨天能正常工作但现在除了 else 语句之外拒绝运行任何东西。
这是我的代码,它会询问用户“你想去哪里?” 然后将收到“房子”的输入。一旦收到此信息,它将打印出他们的指示。取而代之的是,它每次都运行“else”语句。
# Storing the names and directions of users:
David = "Directions to David's home from T... \n East on X, \n South on Y.," \
" \n West on Z., \n South on A., \n first white house on the right."
Caroline = "Directions to Caroline's home from T... \n East on x, \n South on y.," \
" \n East on z., \n South on p., \n East on q," \
" \n West on t., \n last brick house in the cul-de-sac."
William = "Directions to Will's home from T... \n East on x, \n South on y.," \
" \n West on z., \n South on Fa., \n West on b., \n first house on the right."
Bannon = "<Insert directions to Bannon's house>"
# User gives a specific name and then receives a location:
while True:
destination = input("Where would you like to go? ")
if destination.casefold() == 'Davids house':
print(David)
continue
elif destination.casefold() == 'Carolines house':
print(Caroline)
continue
elif destination.casefold() == 'Wills house':
print(William)
continue
elif destination.casefold() == 'Bannons house':
print(Bannon)
continue
# If an invalid location is given, this code will run:
else:
print("Sorry, that location wasn't found! Please try again.")
continue
波斯汪
幕布斯7119047
斯蒂芬大帝
相关分类