Find the error of this python program and correct it. Only try those who know it. Plz it's request.
Share
Find the error of this python program and correct it. Only try those who know it. Plz it's request.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Verified answer
Given code:
x = int("Enter X"))
for in range[0, 11]
if x = y
print x + y
else:
print x - y
Corrected code:
x = int(input("Enter X"))
for y in range(0, 11):
if x == y:
print(x + y)
else:
print(x - y)
1. x = int("Enter X"))
2. for in range[0, 11]
3. if x = y
4. print x + y
5. print x - y
Verified answer
Correct code as follows:
x = int(input("Enter X"))
for y in range(0, 11):
if x == y:
print(x + y)
else:
print(x - y)
Difference between "=" and "==" operators in Python:
Assignment Operator (=)
Assignment operator requires one variable on its left and an expression on its right. Value of the expression on right is assigned to variable on left. Expression and name of variable are not interchangeable.
>>> a=10
>>> b=20
>>> c=a+b
>>> a,b,c
(10, 20, 30)
>>> a+b=c
SyntaxError: can't assign to operator
Equal To or comparison Operator (==)
Equal to operator returns true if operands on either side are equal, otherwise it returns false.
>>> 10+2 == 10
False
>>> (10+2) == 12
True
>>> 'computer' == 'Computer'
False
>>> 'computer' == "computer"
True