Python 5 condition judgment and loop, python judgment Loop

Source: Internet
Author: User

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 {}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.