TypeError in Pycharm (Python) 的中文翻译是 “Pycharm 中的类型错误 (Python)”。

huangapple go评论58阅读模式
英文:

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:

huangapple
  • 本文由 发表于 2023年5月7日 17:35:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76193117.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定