1. 程式人生 > >練習題1

練習題1

coding=utf-8
#用while輸出123456 8910
 i=1
 while i<=10:
     if i==7:
         print()
     else:
         print(i)
     i=i+1
      
 2、求1-100所有數的和
 sum=0
 i=1
 while i<=100:
     sum=sum+i
     i=i+1
 print(sum)
  
  
 輸出1-100內的所有奇數
 i=1
 while i<=100:
     if i%2!=0:
         print(i)
     i=i+1
 # 輸出1-100內的所有偶數
  
 i=1
 while i<=100:
     if i%2==0:
         print(i*i)
     i=i+1
     
      
求1-2+3-4+5.。。99之和
  
 i=1
 sum=0
 while i <100:
     if i%2==0:
         sum=sum-i
     else:
         sum=sum+i
     i=i+1
 print(sum)
         
  
 #使用者登入(三次機會)
 i=1
 while i <4:           
     user=input('請輸入使用者名稱:\n')
     password=int(input('請輸入密碼:\n'))
     if  user=='劉備'  and  password==123:
         print('登陸成功')
     else:
         print('資訊錯誤  請重新輸入')
     i+=1
  
  
  
 name=input('請輸入姓名')
 age=input('請輸入年齡')
 height=input('請輸入身高')
 msg='我叫%s 今年%s 身高%s學習進度為3%%'%(name,age,height)
 print(msg)
乘法口訣
#coding=utf-8
n=1
for i in range(1,10):
    for j in range(1,n+1):
        print('%d*%d=%d\t'%(j,i,j*i),end=' ')
    n=n+1
    print('\n')