KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

A student executes the following program segment and the answer displayed is the wrong output. Name the error. How can the program be modified to get the correct answer?

x = 8, y = 2
    if (x == y)
        print("both are unequal")
    else:
        print("both are equal")

Python Control Flow

1 Like

Answer

Type of error: Syntax error

The program gives the wrong output because it contains syntax errors, such as incorrect variable assignment, missing colon (:) in the if statement, and improper indentation.

The corrected program:

x = 8
y = 2
if (x == y):
    print("both are unequal")
else:
    print("both are equal")

Answered By

3 Likes


Related Questions