0
#!/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.

0

1 Answer 1

1

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