0

I want to print the pattern

hello!
10
8
6
4
2

I have written the following code

print "Hello!";
num=10;
while(num>=2)
   print num;
   num-=2;

Upon execution it is showing syntax error at line 1..

1
  • You need a colon after while condition while num >= 2: Commented Jun 16, 2015 at 7:02

1 Answer 1

2

First of all, do not use semicolons in Python code. There are 2 ways to do this.

1) Using While Loop -

print "Hello!"
num = 10
while num >= 2:
    print num
    num -= 2

2) Using For loop -

print "Hello!"
for i in range(10, 1,-2):
    print i
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.