0

while . if , list in python

i'm trying to code this umur = 18 list = ["bijak", "gg", "pandai"] while True: if umur == 20: print(list[0]) else: print(list[1]) break while umur <= 24: print(umur) umur=umur+1 if umur == 23: print(list[0]) print("test code 1 done") the output of the code is : gg 18 19 20 21 22 bijak 23 24 test code 1 done ok back to the question : all i want to do is , i want to change the position of "bijak" word, like this; can someone show me the way? gg 18 19 20 21 22 23 24 bijak test code 1 done can someone show me the way?

7th Sep 2018, 4:28 PM
riedzman
riedzman - avatar
4 Antworten
7th Sep 2018, 4:46 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 5
so this doesn't happen: umur = 23 print(umur) #23 umur += 1 #umur = 24 if umur == 24: #True print(list[0]) #bijak #--next-- umur <= 24 #True print(umur) #24 and it prints 'bijak' before printing 24
7th Sep 2018, 5:13 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 1
thank you so much
7th Sep 2018, 4:53 PM
riedzman
riedzman - avatar
0
based on your code, umur = 18 list = ["bijak", "gg", "pandai"] while True: if umur == 20: print(list[0]) else: print(list[1]) break while umur <= 24: print(umur) if umur == 24: print(list[0]) umur += 1 print("test code 1 done") >>>>> can you explain why we should put --> umur += 1 <-- below the --> print(list[0]) <-- instead of above it?
7th Sep 2018, 5:06 PM
riedzman
riedzman - avatar