Maison > Article > développement back-end > Jugement conditionnel et bouclage Python
score = 75 if score >= 60: print 'passed'
score = 55 if score >= 60: print 'passed' else: print 'failed'<.>3. La boucle if-elif-else de Python
score = 85 if score >= 90: print 'excellent' elif score >= 80: print 'good' elif score >= 60: print 'passed' else: print 'failed'4. La boucle for de Python
L = [75, 92, 59, 68] sum = 0.0 for x in L: sum = sum + x print sum / 45 La boucle while de Python
sum = 0 x = 1 while x < 100: sum = sum + x x = x + 2 print sum6. break quitte la boucle
sum = 0 x = 1 n = 1 while True: if n > 20: break sum = sum + x x = x * 2 n = n + 1 print sum7. La suite de Python continue la boucle
sum = 0 x = 0 while True: x = x + 1 if x > 100: break if x % 2 == 0: continue sum = sum + x print sum8 La suite de Python continue la boucle
for x in [1, 2, 3, 4, 5, 6, 7, 8, 9]: for y in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]: if x < y: print x * 10 + yPour plus de jugement conditionnel Python. et les articles liés aux boucles, veuillez faire attention au site Web PHP chinois !