Python Forum
Invalid syntax using conditionals if - else
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Invalid syntax using conditionals if - else
#1
Hi, I'm self-taught Python. I use version 3.9.
I wrote simple code to learn how to use the "if" and "else" conditionals, and they worked, but I tried to write more complex code, following my previous examples, and it indicates that there is a syntax error.
Could you help me identify and understand my mistake, please?

My_age = 33 
His_age = int (input ("Write your age: "))
print ("My age less yours is: ", My_age - His_age)
print ("My age plus yours is: ", My_age + His_age)
Question = int (input ("How many years old am I?")
if My_age == Question:
    print ("Correct")
else:
    print ("Incorrect")
Reply
#2
Line 5 doesn't have balanced parentheses.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  print(data) is suddenly invalid syntax db042190 6 1,180 Jun-14-2023, 02:55 PM
Last Post: deanhystad
Question Doubt about conditionals in Python. Carmazum 6 1,591 Apr-01-2023, 12:01 AM
Last Post: Carmazum
  conditionals based on data frame mbrown009 1 889 Aug-12-2022, 08:18 AM
Last Post: Larz60+
  Efficiency with regard to nested conditionals or and statements Mark17 13 3,152 May-06-2022, 05:16 PM
Last Post: Mark17
  Nested conditionals vs conditionals connected by operators dboxall123 8 3,038 Feb-18-2022, 09:34 PM
Last Post: dboxall123
  SyntaxError: invalid syntax ?? korenron 15 5,689 Jan-25-2022, 11:46 AM
Last Post: korenron
  Invalid syntax with an f-string Mark17 7 7,733 Jan-14-2022, 04:44 PM
Last Post: Mark17
  invalid syntax in my class CompleteNewb 2 1,882 Dec-13-2021, 09:39 AM
Last Post: Larz60+
Exclamation Invalid syntax error(Predict Ethereum Price) lulu43366 2 3,146 Sep-24-2021, 01:24 PM
Last Post: lulu43366
  Unexplained Invalid syntax Error cybertooth 5 3,234 Aug-02-2021, 10:05 AM
Last Post: cybertooth

Forum Jump:

User Panel Messages

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