Python 5 condition judgment and loop, python judgment Loop
#! /Usr/bin/env python #-*-coding: UTF-8-*-age = 3if age> = 18: print 'adresult' elif age> = 6: print 'teenager 'else: print 'kid' print '-------------------- 'names = ['jie', 'bob', 'trcy '] for name in names: print nameprint '---------------------- 'sum = 0for x in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]: sum = sum + xprint sumprint U' ----------- range (integer generated) -------------- 'sum = 0for x in range (101 ): sum = sum + xprint sumprint U' ------ while --------------- 'sum = 0n = 3 while n> 0: sum = sum + nn = n-2sum = sum-1 print sumprint u '--------- input raw_input --------------- 'birth = int (raw_input ('birth :')) # note that the data entered by raw_input is the character if birth <20: print u'00 before 'else: print U' after '00'
Note that the code is saved in UTF-8 format.
:
IndentationError: unindent does not match any outer indentation level
This error indicates that the indentation is incorrect.
Print U' ------ while ---------------'
Sum = 0
N = 3
While n> 0:
Sum = sum + n
N = n-2
Sum = sum-1 # indentation error. The Tab is different from the space. The solution is to move sum = sum-1 to the previous line. Press enter and let Editplus wrap the line for us.
Print sum
The interesting thing here is the difference in the position of sum-1 (whether a Tab exists before determines whether the sum = sum-1 Statement belongs to the while {}