英文:
TypeError in Pycharm (Python)
问题
The code you provided has a syntax error. To fix it, you should replace |
with or
to check if the user input contains either "show" or "display." Here's the corrected code:
if "show" in user_action or "display" in user_action:
with open("../files/todos.txt", "r") as file:
todos = file.readlines()
The error you encountered was due to using |
instead of or
for logical OR operations in Python.
英文:
if "show" | "display" in user_action:
with open("../files/todos.txt", "r") as file:
todos = file.readlines()
I want to run the code such that if user input is "show" or "display" then the code line will run.
Error shown:
if "show" | "display" in user_action:
TypeError: unsupported operand type(s) for |: 'str' and 'str'
答案1
得分: 1
将if "show" | "display" in user_action:
替换为if "show" in user_action or "display" in user_action:
。
英文:
Replace
if "show" | "display" in user_action:
to if "show" in user_action or "display" in user_action:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论