user3599374
user3599374

Reputation: 3

Python Simple if

#!/usr/bin/python
import time
a = 0
if a == 5:
    print"Congrats you hit five!"

while a <10:
    a = a + 1
    print a
    time.sleep(.5)

So my program counts to ten no problem.. But it never display the text when a == 5. Any ideas? This is my first attempts at python.

Upvotes: 0

Views: 54

Answers (1)

sshashank124
sshashank124

Reputation: 32197

Your if code should be inside your while loop:

import time
a = 0

while a < 10:
    a = a + 1
    print a
    if a == 5:
        print"Congrats you hit five!"
    time.sleep(.5)

[OUTPUT]
1
2
3
4
5
Congrats you hit five!
6
7
8
9
10

Upvotes: 1

Related Questions