Python 5 conditional judgment and looping

Source: Internet
Author: User

#!/usr/bin/env python#-*-Coding:utf-8-*-age = 3if age >= 18:print ' adult ' elif age >= 6:print ' teenager ' Else:prin T ' 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 generation)---------------- ' Sum = 0for x in range (101): sum = sum + xprint sumprint u '------while---------------' sum = 0n = 3while n>0:sum = sum + nn = N-2sum = sum-1print sumprint u '---------input raw_input---------------' birth = Int (raw_input (' Birth: '))   #注意raw_in Put input data are characters if birth<20:print u ' 00 ago ' else:print u ' 00 after '

Note the format in which the code is saved is Utf-8

:

Indentationerror:unindent does not match no outer indentation level

This error is telling us that indentation is not right.

Print U '------while---------------'
sum = 0
n = 3
While n>0:
sum = SUM + N
n = n-2
sum = sum-1 #容易出现缩进错误, the difference between tab and space, the solution is sum = sum-1 move to the previous line, carriage return let EditPlus help us break
Print sum
Here's the interesting thing. Sum = the difference in the position of the sum-1 (before the tab, determines whether the sum = sum-1 statement belongs to while{}


Python 5 conditional judgment and looping

Related Article

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.