find error in following code and acorrect it by re writting it and underline the correction
x=int("Enter value for x:"))
for in range [0,11];
if x = y
print x+y
else :
print x-y
Answers
Answered by
1
Answer:
x=int(input("Enter value for x:"))
for y in range (0,11):
if x == y:
print x+y
else :
print x-y
Explanation:
Answered by
10
Given code:
x=int("Enter value for x:"))
for in range [0,11];
if x = y
print x+y
else :
print x-y
Errors:
1) x=int("Enter value for x:"))
- Since the value needs to be entered by the user, the input() function must be used.
2) for in range [0,11];
- There is no variable given in the loop.
- The brackets used for the range function should be () and not [].
- After the statement given for the loop, there should be a colon (:), not a semi-colon (;).
3) if x = y
- There should be two "=" symbols, indicating that the given statement must be checked for.
- After the test expression, there must be a colon (:).
4) print x + y
- There must be brackets when giving the code to be printed.
5) else :
- No spaces after the test expression.
6) print x - y
- There must be brackets when giving the code to be printed.
Corrected code:
x = int(input("Enter the value for x: "))
for y in range(0, 11):
if x == y:
print(x + y)
else:
print(x - y)
Similar questions
Math,
3 months ago
Social Sciences,
3 months ago
English,
3 months ago
Math,
7 months ago
Math,
1 year ago
Social Sciences,
1 year ago
Chemistry,
1 year ago