Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SyntaxError: invalid syntax
#1
hey guys, i just start programming with python,

and idk why im getting this syntax error, SyntaxError: invalid syntax. Perhaps you forgot a comma?,

this is the lines that gets the error:

task_name = input("Enter To day's Task: ")
    Tasks.append(task_name)
i don't understand i did this last time and there were no errors,

so i don't get it did i write the syntax wrong or what i don't know
Reply
#2
(Apr-28-2026, 07:00 AM)Fortuitous Wrote: so i don't get it did i write the syntax wrong or what i don't know
Read carefully the error message printed by the Python interpreter. What does it say?
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
Your Task for today must be to make a list called Tasks and then append items to the list Tasks

.append() is used with a Python list to add items to the list, like this:

Tasks.append(something)

I entered these these activities as my tasks for each day:

Quote:fry eggs
pick strawberries
find a girlfriend
as tasks each time round.

# a list of days
days = ['Monday', 'Tuesday', 'Wednesday']

# make an empty list
tasks = []
for day in days:
    task_name = input(f"Enter {day}'s task: ") # be careful with 's you may need to escape the ' if you don't use " front and back
    tasks.append(day + ': ' + task_name)

# show the items saved in the list tasks
for t in tasks:
    print(t)
You will see:

Output:
Monday: fry eggs Tuesday: pick strawberries Wednesday: find a girlfriend
# perhaps a dictionary is better here, instead of a list
# make an empty dictionary
tasks_dict = {}
for day in days:
    task_name = input(f"Enter {day}'s task: ") # be careful with 's you may need to escape the ' if you don't use " front and back
    tasks_dict[day] = task_name

# show the items saved in tasks_dict
# you can get data from a dictionary using the dictionary keys
for key in tasks_dict.keys():
    print(key, tasks_dict[key])
You will see:

Output:
Monday fry eggs Tuesday pick strawberries Wednesday find a girlfriend
Hope Wednesday works out!
Reply
#4
(Apr-28-2026, 07:00 AM)Fortuitous Wrote:
task_name = input("Enter To day's Task: ")
    Tasks.append(task_name)
i don't understand i did this last time and there were no errors,

Guess Mode: Indentation is wrong, Tasks.append has the wrong indentation.

If you use a modern Python Version (+3.14) you will get better error messages.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  print(data) is suddenly invalid syntax db042190 6 5,159 Jun-14-2023, 02:55 PM
Last Post: deanhystad
  SyntaxError: invalid syntax ?? korenron 15 11,749 Jan-25-2022, 11:46 AM
Last Post: korenron
  Invalid syntax with an f-string Mark17 7 22,758 Jan-14-2022, 04:44 PM
Last Post: Mark17
  invalid syntax in my class CompleteNewb 2 4,316 Dec-13-2021, 09:39 AM
Last Post: Larz60+
Exclamation Invalid syntax error(Predict Ethereum Price) lulu43366 2 4,995 Sep-24-2021, 01:24 PM
Last Post: lulu43366
  Unexplained Invalid syntax Error cybertooth 5 7,267 Aug-02-2021, 10:05 AM
Last Post: cybertooth
  [split] SyntaxError: invalid syntax Code_X 3 4,455 May-04-2021, 05:15 PM
Last Post: Yoriz
  Invalid syntax error - need help fixing calgk01 3 5,431 Feb-23-2021, 08:41 PM
Last Post: nilamo
  Invalid syntax using conditionals if - else jperezqu 1 3,439 Jan-13-2021, 07:32 PM
Last Post: bowlofred
  invalid syntax in line 5. Help Asadzangibaloch 2 3,794 Dec-10-2020, 04:26 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020