The Python for loop and while loop

format for statement 
for x in range (start value, end value, the stride)
  execute the statement
output 0,100 individual numbers
for I in Range (0,101)
  Print (I)
output of 0,100 even
for i in range (0,101,2)
  print (i)
output a sum of the values
a = [ '. 1', '2', '. 3']
for I in a:
  print (i)
while sentence format
while Analyzing formula:
  execute statement
output 0,100 each number

i = . 1
the while I <= 100:
  Print (I)
  I + =. 1
. 1 title: number of Penta

  f=0
  c=0
  for i in range(1,101):
    f=i*(3*i-1)/2
    print('%-5.2d '%(f),end="")
    c=c+1
    if(c%10==0):
      print('\n')

Several input number to 0 to end, and a mean value is calculated

Positive_number=0
negative_number=0
s=0
i=0
num=int(input('请输入数: '))
while num!=0:
    if num>0:
        Positive_number=Positive_number+1
        i=i+1
    elif num<0:
         negative_number=negative_number+1
          i=i+1
    s=s+num
    num=int(input('请输入数: '))
print(Positive_number,negative_number,s/i)         

 

Guess you like

Origin www.cnblogs.com/shy13138/p/11298440.html