Q.Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code. 250 = Number WHILE Number<=1000: if Number=>750: print Number Number=Number+100 else print Number*2 Number=Number+50
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →The code has several syntax errors: the assignment is reversed, WHILE must be lowercase, => should be >=, else needs a colon, and print needs parentheses. Corrected, it is a valid while loop that runs from 250 up to 1000.
The Concept: Fixing Syntax Errors in Python
Python is strict about its syntax — it does not forgive a reversed assignment, a wrong operator order, a missing colon, or a Python-2 style print. We fix each error in turn and underline the correction.
Step-by-Step Correction
1. Fix the initial assignment
250 = Number is backwards — you cannot assign to a literal. The variable name goes on the left:
Number = 250
2. Fix the WHILE loop header
WHILE must be lowercase while (Python keywords are case-sensitive):
while Number <= 1000:
3. Fix the if condition
Number=>750 uses an invalid operator. The correct "greater than or equal to" is >=:
if Number >= 750:
4. Add the missing colon after else
else:
5. Add parentheses to print
In Python 3, print is a function, so its argument must be in parentheses:
print(Number)
print(Number * 2)
A common mistake is writing => instead of >=. The = always comes after the > or < — read it as "greater than or equal". Likewise <= means "less than or equal".
The Corrected Code
Each change is underlined (<u>...</u>):
<u>Number = 250</u>
<u>while</u> Number <= 1000:
if Number <u>>=</u> 750:
<u>print(Number)</u>
Number = Number + 100
<u>else:</u>
<u>print(Number * 2)</u>
Number = Number + 50
``` …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.