#๐Ÿ”’ Need simple help with an error

17 messages ยท Page 1 of 1 (latest)

tough obsidian
#

My code is not working

next warrenBOT
#

@tough obsidian

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

tough obsidian
#

file = input("File name: ")
match file:
case file.endswith('.gif'):
print("image/gif")

#

i get an TypeError: called match pattern must be a class

#

i wanted my code to print image/gif if the string file ends with .gif

modern comet
#

use an if-statement, not match

elfin fox
#

use if/elif/else statements for that, not match/case

tough obsidian
#

okay, thank you

modern comet
#

match-cases use patterns, not expressions, they do not evaluate to any values so you can't use them exactly like if-statements

elfin fox
#

match/case is used when you want to test complex conditions that vary based on the object's type

tough obsidian
#

Okay

bright cradle
#
file = input("File name: ")

if file.endswith('.gif'):  # use a simple if-else statement
    print("image/gif")
else:
    print("Unknown file type")  # optionally, handle other file types
#

@tough obsidian ^^

next warrenBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

๐Ÿ”’ Need simple help with an error