Python loop: for

Source: Internet
Author: User

Note Else's location:

The first type:

#!/usr/bin/python#-*-coding:utf-8-*- forIinchRange (10,20):     forNuminchRange (2, i):ifI%num = =0:j= i/NumPrint "%d =%d *%d"%(I,NUM,J) Break    Else:        PrintI"is a prime number"Output Result:10 = 2 * 511is a prime number12 = 2 * 613is a prime number14 = 2 * 715 = 3 * 516 = 2 * 817is a prime number18 = 2 * 919 is a prime number

The second Kind

#!/usr/bin/python#-*-coding:utf-8-*- forIinchRange (10,20):     forNuminchRange (2, i):ifI%num = =0:j= i/NumPrint "%d =%d *%d"%(I,NUM,J) Break        Else:            PrintI"is a prime number (i), the value of num is:", num outputs the result:10 = 2 * 511 is a prime number (i), the value of num is: 211 is a prime number (i), the value of num is: 311 is a prime number (i), the value of num is: 411 is a prime number (i), the value of num is: 511 is a prime number (i), Num's value is: 611  is a prime number (i), the value of num is: 711 is a prime number (i), the value of num is: 811 is a prime number (i), the value of num is: 911 is a prime number (i), the value of num is: 1012 = 2 * 613 is a prime number (i), the value of num is: 213 is a prime number (i), the value of num is: 313 is a prime number (i), the value of num is: 413 is a prime number (i), the value of num is: 513 is a prime number (i), the value of num is: 613 is a prime number (i), the value of num is: 713 is a prime The value of M is: 813 is a prime number (i), the value of num is: 913 is a prime number (i), the value of num is: 1013 is a prime number (i), the value of num is: 1113 is a prime number (i), the value of num is: 1214 = 2 * 715 is a prime (i), n The value of UM is: 215 = 3 * 516 = 2 * 817 is a prime number (i), the value of num is: 217 is a prime number (i), the value of num is: 317 is a prime number (i), the value of num is: 417 is a prime number (i), the value of num is: 517 is a A prime number (i), the value of num is: 617 is a prime number (i), the value of num is: 717 is a prime number (i), the value of NUM is: 817 is a prime number (i), the value of num is: 917 is a prime number (i), the value of num is: 1017 is a prime Values are: 1117 is a prime number (i), the value of num is: 1217 is a prime number (i), the value of num is: 1317 is a prime number (i), the value of num is: 1417 is a prime number (i), the value of num is: 1517 is a prime number (i), the value of num is: 161  8 = 2 * 919 is a prime number (i), the value of NUM is: 219 is a prime number (i), the value of num is: 319 is a prime number (i), the value of num is: 419 is a prime number (i), the value of num is: 519 is a prime number (i), Num's value is: 619 is a prime number (i), the value of num is: 719 isA prime number (i), the value of num is: 819 is a prime number (i), the value of num is: 919 is a prime number (i), the value of num is: 1019 is a prime number (i), the value of num is: 1119 is a prime number (i), num is: 1219 is a prime (i), n The value of UM is: 1319 is a prime number (i), the value of num is: 1419 is a prime number (i), the value of num is: 1519 is a prime number (i), the value of num is: 1619 is a prime number (i), the value of num is: 1719 is a prime number (i), the value is: 18
View Code

Python loop: for

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.