使用for循環和while循環打印三角形(附九九乘法表實現)
for循環方法:
i = 0
for tmp in range(6):
print("*"*tmp)
while循環方法:
i = 0
while i <= 5:
print("*"*i)
i += 1
效果如下:
*
**
***
****
*****
同理我們可以輸出九九乘法表:
for循環方法:
for i in range(1,10):
for j in range(1,i+1):
print("%dx%d=%d\t" %(j, i, j*i), end="")
print("")
while循環方法:
i = 1
while i <= 9:
#定義列
j = 1
while j <= i: #\t制表符,相當於一個Tab鍵
print("%dx%d=%d\t" %(j, i, j*i), end="")
j += 1
print("")
i += 1
使用for循環和while循環打印三角形(附九九乘法表實現)
相關推薦
使用for循環和while循環打印三角形(附九九乘法表實現)
九九乘法表使用for / while循環輸出帶*三角形for循環方法: i = 0 for tmp in range(6): print("*"*tmp) while循環方法: i = 0 while i <= 5: print("*"*i) i += 1 效果如下: * **
python基礎5 if-else流程判斷,for循環和while循環
代碼 整數和 data valid 語法錯誤 usr 定義 small 提示 本節主要內容: if-else流程判斷 for循環 while循環 參考網頁 if-else流程判斷 if 語句概述 計算機之所以能做很多自動化的任務,因為它可以自己做條件判斷。 比如,輸入用
用Shell編寫for循環和while循環案例
linux for while (1)Shell中的單引號和雙引號區別??A="www.jfedu.net" ??B=‘$A‘?echo $B註釋:?? ? ? ? ? ?把www.jfedu.net賦值給變量A,?把變量A的內容賦值給變量B,打印出變量B的結果,打印出的結果為$A? ? ? ?
for循環和while循環
執行流程 while 個數 初始化 使用場景 switch語句 一次 跳轉語句 spa 1.for循環語句的格式: for(初始化語句;判斷條件語句;控制條件語句){ 循環體語
練習:for循環和while循環
bubuko png tdi windows 分享圖片 inux int nbsp ++ #include <stdio.h>#include <windows.h>int main(void){ int a; //定義一個整數型變量 for(a=1
Python學習筆記(3)for循環和while循環
循環語句 con while循環 art start 開始 count als 一輪 2019-02-25 (1)break語句:終止當前循環,跳出循環體。 (2)continue語句:終止本輪循環並開始下一輪循環(在下一輪循環開始前,會先測試循環條件)。 (3)fo
for和while循環小練習
() code 代碼 += 但是 app count while 都是 用for和while循環,對數字列表/數字元組中的元素進行求和:用for實現>>> val = 0>>> l1 = [1,3,5,7,9]>>> f
用for和while循環求e的值[e=1+1/1!+1/2!+1/3!+1/4!+1/5!+...+1/n!]
主函數 int class urn log emp art print tracking /*編敲代碼,依據下面公式求e的值。要求用兩種方法計算: 1)for循環。計算前50項 2)while循環,直至最後一項的值小於10-4 e=1+1/1!+1/2!+1/
Oracle中的for和while循環
current tle 過程 while循環 let lob -- when rom 實例: beginfor i in 51..500 loop delete from test t where t.date=to_date(‘2016-07-01‘, ‘yyyy-M
四、Oracle loop循環、while循環、for循環、if選擇和case選擇、更改讀取數據、遊標、觸發器、存儲過程
bsp 邏輯或 pda 傳遞依賴 函數 名稱 執行 count 記錄 數據庫的設計(DataBase Design): 針對於用戶特定的需求,然後我們創建出來一個最使用而且性能高的數據庫! 數據庫設計的步驟: 01.需求分析 02.概念
python學習之break和continue在for循環中的使用(案例:打印出10以內的偶數,並且只要前三個偶數)
com python學習 bsp 次循環 bubuko python alt info 偶數 運行程序,break是整個程序都跳出 continue則表示跳過當前一次循環,然後繼續執行循環 python學習之break和continue在for循環中的使用(案例:打
(字符串的操作 for循環 和 while遍歷循環)
isdigit find 計數 capi 劉德華 序列 apc 負數 itl 1)字符串是什麽,和字符串的常用操作方法 1,什麽是字符串. 字符:是單一的文字符號, 字符串:是有序的字符序列,由" ‘ ‘‘‘ """引起來的內容就是字
python while 循環打印九九乘法表
pan str family soft 9*9 方向 mil ros end 方向一 i = 1 while i <= 9: j = 1 while j <= i print(‘%d*%d = %2d‘%( j,i ,i*j),en
用戶輸入和while循環
ont 數字 暫停 實參 ann sage 回車 轉化 put 函數input()可以讓程序暫停執行,等待用戶輸入後,按回車繼續執行。 message = input(”請輸入:“) print(message) 通常輸入的東西程序會默認其為字符串,若想轉化為數字,需要
for循環、while循環、break循環、continue結束本次循環、exit退出整個腳本
核心 一次 src 郵件告警 aso 分隔符 fuse crypt 語句 for循環 for循環案例1 #打印1到100 [root@garytao-01 shell]# vi for1.sh [root@garytao-01 shell]# cat for1.sh
7、read的使用和while循環
read while循環read使用如下實例,如果給的變量和參數個數一樣就對應給變量賦值(如下圖1),如果變量多了,對應賦值,後面的變量為空(如下圖3)如果變量少了,就對應賦值,最後一個變量全部賦值給剩余的參數(如下圖2) 下面-n是不換行 有時候想要結合echo和read去使用一種顏色的輸入顯示就可以這
2018-4-19 17周2次課 for循環、while循環、break、continue、exit
shell20.10 for循環·語法:for 變量名 in 條件; do …; done案例1計算1到100數字的和#!/bin/bash sum=0 for i in `seq 1 100` do sum=$[$sum+$i] ##核心語句 echo $i d
for循環,while循環
for while循環for循環 1.語法:for in do done [root@weixing01 shell]# cat for.sh #!/bin/bash sum=0 for i in `seq 1 100` do sum=$[$sum+$i] done echo $sum [roo
for循環、while循環、break跳出循環、continue結束本次循環、exit退出本次腳本
for循環 while循環 break跳出循環 continue結束本次循環 exit退出腳本 for循環 格式: for i in `seq 1 3` //表示從1-3,運行3次,i=1,i=2,i=3; do echo $i
for循環、while循環、continue、break、exit解析、select用法
for循環、while循環、contin20.10 for循環 eg: 求1到100數字的和。[root@localhost sbin]# vim sum.sh#!/bin/bashsum=0for i in seq 1 5dosum=$[sum+$i]doneecho "$sum" [r