-2

I am coding a to-do app, but while matching the menu() function it gives a Syntax Error, the function returns the number of the option the user selected, this is the code:

# Imports
import time, os, random
from colorama import Fore, Back, Style

# Functions
def menu():
  print(f"{Fore.BLUE}To-Do List!")
  print(Style.RESET_ALL)
  print(f"{Fore.GREEN}[1] ADD ITEM")
  print(f"{Fore.RED}[2] REMOVE ITEM")
  print(f"{Fore.BLUE}[3] SEE LIST")
  option = int(input("Selection > "))
  return option

# Variables  
newItem = {
  "name": "",
  "description": "",
  "date": "",
  "priority": ""
}

todo = []

# Code
match menu():
  case 1:
    os.system("clear")
    print(f"{Fore.GREEN}ADD ITEM TO LIST")
    print(Style.RESET_ALL)
    newItem["name"] = input("Item name > ")
    newItem["description"] = input("Item description > ")
    newItem["date"] = input("Item date > ")
    newItem["priority"] = input("Item priority (low/med/high) > ")
    todo.append(newItem)
    print(todo)
    input()

How can I solve it?

I tried changing the variable and using the match() statement a different way, it still has the same error.

Michael M.
  • 10,486
  • 9
  • 18
  • 34
  • Which version of python you are using? – Abdul Niyas P M Jan 31 '23 at 07:42
  • 3
    I think the `match` statement was added in v3.10. - https://peps.python.org/pep-0634/#the-match-statement – CryptoFool Jan 31 '23 at 07:45
  • 1
    Are you using python version 3.10? I use python 3.10 and it didn't give me any error. – Aryan Arora Jan 31 '23 at 07:45
  • 1
    Can you [edit] to post the actual error message? – Gino Mempin Jan 31 '23 at 08:16
  • 1
    Welcome to Stack Overflow. Please read [ask] and [mre]. Try to create the *shortest* code you can think of that *directly* demonstrates the error (i.e., someone else should be able to copy and paste it, run it without doing anything, and directly see the exact problem); then show a [complete](https://meta.stackoverflow.com/questions/359146) error message corresponding to that example. – Karl Knechtel Jan 31 '23 at 08:20
  • Assuming this is because of the Python version, the canonical is https://stackoverflow.com/questions/69725962. – Karl Knechtel Jan 31 '23 at 08:24

1 Answers1

0

As @CryptoFool already mentioned in the comments, the match statement was added in python 3.10. Means, previous versions won't work.

Make sure to install a python version greater or equal to 3.10, or use a workaround

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
kaliiiiiiiii
  • 925
  • 1
  • 2
  • 21