Computer Science
Find errors (if any) in the following code and rewrite the code underlining each correction:
x = int("Enter value of x:")
for in range[0, 10]:
if x = y
print("They are equal")
else:
Print("They are unequal")
Python Control Flow
8 Likes
Answer
x = int("Enter value of x:") #Error 1
for in range[0, 10]: #Error 2
if x = y #Error 3
print("They are equal")
else:
Print("They are unequal") #Error 4
Error 1 — The input()
function is missing from the code to prompt the user for input.
Error 2 — The syntax of the range()
function uses parentheses () rather than square brackets [] and the variable y
is missing in the for
loop declaration (for y in range(0, 10):)
.
Error 3 — The comparison operator in the if
statement has = (assignment) instead of == (equality comparison) and colon (:) is missing at the end.
Error 4 — The print function should be written with a lowercase 'p' for proper syntax.
The corrected code is:
x = int(input("Enter value of x:"))
for y in range(0, 10):
if x == y:
print("They are equal")
else:
print("They are unequal")
Answered By
3 Likes
Related Questions
Which protocol is used to create a connection with a remote machine?
Which of the following cannot be returned by random.randrange(4) ?
- 0
- 3
- 2.3
- None of these
Mr. William wants to remove all the rows from table INVENTORY to release the storage space but he does not want to remove the structure of the table. What MySQL statement should he use?
A computer or a device that requests resources or data from the server is called …………… .