I have this piece of code, where it prints the numbers from 0-24 and it prints you need a break when time is equal to 8, 16, 24, now the point is when time is 8, 16 and 24 it prints the time and the statement '8 you need to take a break', but also after it iterates the code, beneath the time and statement it print the time again, can you please explain how to avoid this?
time=0
while time!=25:
if time%8==0 and time!=0:
print (time,'you need to take a break')
if time == 25:
time=0
print (time)
time+=1
This is the result i get.
0
1
2
3
4
5
6
7
8 you need to take a break
8
9
10
11
12
13
14
15
16 you need to take a break
16
17
18
19
20
21
22
23
24 you need to take a break
24
And this is want i want to get
0
1
2
3
4
5
6
7
8 you need to take a break
9
10
11
12
13
14
15
16 you need to take a break
17
18
19
20
21
22
23
24 you need to take a break
Aucun commentaire:
Enregistrer un commentaire