112k views
0 votes
Can you identify one syntax error and one logic error in these lines? How do you think you could avoid making logic errors like the one in this code?

You are creating a program in which the user will input his or her age. The program will calculate the year that the user was born and will then tell the user which decade he or she was born in. Here is part of the code:if year > 1989 and year < 2000 print("You were born in the 1980s")

1 Answer

4 votes

Answer:

(a) Syntax Error: Missing colon symbol

(b) Logic Error: The condition is wrong

Step-by-step explanation:

The programming language is not stated; so, the syntax error may not be correctly identified.

Assume the programming language is Python, then the syntax error is the missing colon symbol at the end of the if statement. This is so because, Python required a colon symbol at the end of every if condition statement.

The logic error is also in the condition.

The condition states that all years later than 1989 but earlier than 2000 are 1980s. This is wrong because only years from 1980 to 1989 (inclusive) are regarded as 1980s.

User Last
by
4.7k points