January 23 "Basic knowledge of Python3"

Source: Internet
Author: User

January 23 "Basic knowledge of Python3"

3.1 If/while/for
3.2 Solving Math Puzzles
3.3 Python Instance

3.1 If/while/for
‘‘‘#if 判断条件:    执行语句elif 判断条件:    执行语句else:    执行语句#while 判断条件:    执行语句# break: 跳出循环#continue: 跳出当次循环#for item in sequence:    执行语句‘‘‘# lsit 遍历l = [‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘]for x, y in enumerate(l):    print(x, y)
3.2 Solving Math Puzzles
# ABCD * 9 = DBCA  答案:A=1 B=0 C=8 D=9for A in range(1, 10):    for B in range(0, 10):        for C in range(0, 10):            for D in range(1, 10):                start = 1000 * A + 100 * B + 10 * C + D                end = 1000 * D + 100 * C + 10 * B + A                if start * 9 == end:                    print("A={0};B={1};C={2};D={3}".format(A, B, C, D))                    print("{0} * 9 = {1}".format(start, end))
3.3 Python Instance
# 阶乘相加def one(n):    total = 1    if n == 0:        total = 1    else:        for i in range(1, n+1):            total *= i    return totalresult = 0n = int(input("输入<=0的数字:"))for i in range(0, n+1):    result += one(i)print(result)

January 23 "Basic knowledge of Python3"

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.