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?
4 ответов
+ 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
+ 1
thank you so much
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?