Python while loop and double loop

Source: Internet
Author: User

#python中, the While statement is used to loop the execution of a program that, under certain conditions, loops through a program to handle the same tasks that require repeated processing.
#while是 the "as type" loop structure.
I=1
While i<=20:
Print (i,end= "")
I+=1

Sum=0
I=1
While i<=100:
Sum+=i
I+=1
Else
Print ("\ n", sum)

Print ("0+2+...+100=", sum)
#从控制台录入一个数字, the factorial from 1 to the number;
result=1;i=1;numa=0;
Numa=int (Input ("Please enter a number:"))
While I<=numa:
Result*=i
I+=1
Else
Print ("Loop over!")
Print ("Result is:", result)
#使用while循环输出100以内的素数
x=2
While x<100:
n=2
While N<x-1:
If x%n==0:
Break
N+=1
Else
Print (x,end= "")
X+=1
Else
Print ("Loop End")
#输出100之内能被7整除的数
nnum=7;linecount=0;
While nnum<=100:
If nnum%7!=0:
Nnum+=1;
Continue
Else
Print (nnum,end= "")

lineCount+=1if lineCount==5:    print()  #单个print()换行;    lineCount=0nNum+=1;

Else
Print ("\ n Loop End")
#使用while循环计算从1到100之和
Sum=0;i=1;
While i<=100:
Sum+=i;
I+=1;
Else
Print ("1+2+3+...+100=", sum);
Print ("\ n Program End")
the number of #从控制台录入打印 symbols.
row=0;i=0;
Row=int (Input ("Enter Number of lines:"));
While I<row:
Print ()
Print (
"", end= "")
I+=1;
Else
Print ("\ n program run End")
#使用while循环和for循环嵌套. The Python language allows another loop body to be nested within one loop body.
#实例: Enter the number of rows and columns from the console to print the square.
I=1;j=1;
Numa=int (Input ("Enter Number of lines:"))
Numb=int (Input ("Please enter number of columns:"))
While I<=numa:
J=1
While J<=numb:
Print ("*", end= "")
J+=1
Print ()
I+=1

#使用while循环嵌套打印九九乘法口诀表;
I=1;j=1;
While i<=9:
J=1
While J<=i:
Print ("%d%d=%2d"% (J,i,ij), end= "")
J+=1
Print ()
I+=1
Else
Print ("\ n program run End")

#使用for循环打印九九乘法口诀表;
For I in Range (1,10):
For j in Range (1,10):
If j<=i:
Print ("%d%d=%2d"% (J,i,ij), end= "")
Else
Print ()
Else
Print ("\ n program run End");

Python while loop and double loop

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.