python基礎 while迴圈練習
導讀 | 這篇文章主要給大家分享的是5道關於python基礎 while迴圈練習題,無論學習什麼語言,練習都是必不可少的,下面文章的練習題挺精湛的,需要的朋友可以參考一下 |
1. 使用while迴圈輸出1 2 3 4 5 6 8 9 10
count=0 while count <10: count+=1 print(count)
2. 求1-100的所有數的和
count=0 total=0 #定義兩個變數 while count <=100: total +=count # 每迴圈一次,total的count都需要累計加一次 count=count+1 #每迴圈一次,count都需要增加1 print(total) #輸出結果
3. 輸出 1-100 內的所有奇數
count=1 while count<=100: if count%2 != 0: print(count) count+=1
4.輸出 1-100 內的所有偶數
count=1 while count<=100: if count%2 != 1: print(count) count+=1
5. 使用者登陸(三次機會重試)
while count<3: name=input("請輸入使用者名稱") password=input("請輸入密碼") if name=="huxiaohui" and password=="123456": print("你答對啦") break else: print("錯啦 再來一次") count+=1
原文來自:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69955379/viewspace-2847365/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Python學習-while迴圈練習PythonWhile
- Python基礎-While迴圈語句PythonWhile
- C#練習,應用for,while,do-while迴圈C#While
- javascript基礎(控制流程(迴圈 while,for))(十二)JavaScriptWhile
- python while迴圈PythonWhile
- Java基礎 迴圈語句 for while do.....while語句JavaWhile
- Python基礎學習之迴圈Python
- Matlab的if語句switch語句for迴圈while迴圈語句練習MatlabWhile
- python 基礎 迴圈Python
- C語言——迴圈結構(for迴圈,while迴圈,do-while迴圈)C語言While
- C#程式設計基礎第七課:C#中的基本迴圈語句:while迴圈、do-while迴圈、for迴圈、foreach迴圈的使用C#程式設計While
- python學習手冊13:while及for迴圈PythonWhile
- while迴圈While
- java學習之while迴圈JavaWhile
- Python基礎(07):迴圈Python
- C語言程式設計學習中while迴圈和do……while迴圈C語言程式設計While
- 15-python之while迴圈PythonWhile
- Java入門學習-學習if & else,for迴圈,foreach迴圈,while迴圈的用法。JavaWhile
- 【Python基礎】for迴圈語句Python
- Python基礎教程06 - 迴圈Python
- PHP For & While 迴圈PHPWhile
- python04: while迴圈語句 break continue for in 迴圈PythonWhile
- Java 迴圈 - for, while 及 do…whileJavaWhile
- 04流程控制 for迴圈,while迴圈While
- 大資料之JAVA基礎(五):迴圈和陣列方法練習大資料Java陣列
- linux while 迴圈LinuxWhile
- while迴圈補充While
- Python基礎練習題Python
- 迴圈高階綜合練習
- 【基礎題】【for迴圈】二重迴圈
- Python基礎:條件判斷 & 迴圈Python
- Python 快速教程(基礎篇06): 迴圈Python
- Python中for迴圈和while迴圈有什麼區別?Python入門教程PythonWhile
- Java迴圈結構-for,while及do…whileJavaWhile
- Java while和do while迴圈詳解JavaWhile
- Python學習小結—使用者輸入和While迴圈PythonWhile
- JavaScript中的while迴圈JavaScriptWhile
- Python趣味入門5:迴圈語句whilePythonWhile