It will print start and stop, but not on the first line? How can I get “START!” to print after the first line of asterisks when I run it, rather than just the changes of direction?
JavaScript
x
41
41
1
import time, sys
2
3
while True:
4
try:
5
print("Enter and integer between 5 and 15: ")
6
userInput = int(input())
7
if userInput < 5 or userInput > 15:
8
continue
9
else:
10
break
11
except ValueError:
12
print("You must enter an integer.")
13
continue
14
15
stars = ''
16
17
indent = 0
18
indentIncreasing = True
19
20
try:
21
stars += "*" * userInput
22
while True:
23
print(' ' * indent, end='')
24
print(stars)
25
time.sleep(0.1)
26
27
if indentIncreasing:
28
indent = indent + 1
29
if indent == 20:
30
print(' ' * 20 + stars + " STOP!")
31
indentIncreasing = False
32
33
else:
34
indent = indent - 1
35
if indent == 0:
36
print(stars + " START!")
37
indentIncreasing = True
38
39
except KeyboardInterrupt:
40
sys.exit()
41
Advertisement
Answer
How about just adding a print statement before the while
loop and initializing indent
at 1 instead of 0?
JavaScript
1
11
11
1
indent = 1
2
indentIncreasing = True
3
4
try:
5
stars += "*" * userInput
6
print(stars + ' START!')
7
while True:
8
print(' ' * indent, end='')
9
print(stars)
10
time.sleep(0.1)
11