Mudit Maheshwari
Mudit Maheshwari

Reputation: 11

syntax error in printing String

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..

Upvotes: 0

Views: 48

Answers (1)

Vikas Ojha
Vikas Ojha

Reputation: 6950

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

Upvotes: 2

Related Questions