Learn Before
Code
SyntaxError Example
current_time_str = input("What is the current time (in hours 0-23)?") wait_time_str = input("How many hours do you want to wait" current_time_int = int(current_time_str) wait_time_int = int(wait_time_str) final_time_int = current_time_int + wait_time_int print(final_time_int)
SyntaxError: bad input on line 4
The SyntaxError generated above is produced by the missing end parenthesis in line 2. This may be confusing because line 4 itself does not contain a syntax error. Since Python allows statements to continue over multiple lines inside parentheses, Python will continue to scan subsequent lines looking for the balanced right parenthesis. However in this case it finds the namecurrent_time_int and it will want to interpret that as another parameter to the input function. But, there is not a comma to separate the previous string from the variable so as far as Python is concerned the error here is a missing comma on line 4.
0
1
Updated 2021-06-22
Tags
Python Programming Language
Data Science