Python Forum
Getting syntax error, no clue why
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting syntax error, no clue why
#1
I dont know if I am just dumb and not seeing what is going on but I am so confused.....

the issue I am having is
 birthday = input("Have you had your birthday this year? ")
and getting a syntax error pointing at the variable name. What is going on? the two lines previous look exactly the same and are not having any issues.
Reply
#2
Often with the SyntaxError the error is indeed on the line before where it is indicated.
Post the full code or at least couple of lines before and after that one
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
its not a very long script, and it is fairly simple so i will just post all of it.
import time
from datetime import date

name = input("What is your name? ")
age = int(input("How old are you? ")
birthday = input("Have you had a birthday this year? ")

if birthday == "yes" and age != "":
    oldAge = (date.today().year - age) + 100
elif birthday == "no" and age != "":
    oldAge = (date.today().year - (age + 1)) + 100
else:
    print("Your age must be a number!")

output = f"Your name is {name}, and you will be 100 years old in {oldAge}!"
print(output)

repeat = input("Pick a number between 1 and 100: ")
count = 0

if int(repeat) > 0:
    for num in range(int(repeat)):
        print(output + "\n")
Reply
#4
yep, there is missing closing bracket on line 5
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Oh my gosh, thank you.... simple mistakes amiright. lol. This makes me sad as I have been coding in python everyday for over a month and this is probably the simplest thing I have done in a few weeks and it was just driving me nuts. Thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax error for "root = Tk()" dlwaddel 15 1,007 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 333 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 1,450 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,135 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 1,249 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,194 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 847 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 1,777 Sep-17-2022, 04:09 AM
Last Post: jttolleson
  I have no clue what I am doing wrong here elroberto 4 1,332 Jun-18-2022, 08:56 PM
Last Post: deanhystad
  Mysql Syntax error in pymysql ilknurg 4 2,287 May-18-2022, 06:50 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

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