Python练习-2
生活随笔
收集整理的這篇文章主要介紹了
Python练习-2
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#1、使用while循環輸入 1 2 3 4 5 6 8 9 10
count = 0
while count < 10:count += 1 # count = count + 1if count == 7:print(' ')else:print(count) count = 0
while count < 10:count += 1 # count = count + 1if count == 7:continueprint(count) #3、輸出 1-100 內的所有奇數
#方法一:
count = 1
while count < 101:print(count)count += 2
#方法二:
count = 1
while count < 101:if count % 2 == 1:print(count)count += 1
#5、求1-2+3-4+5 ... 99的所有數的和 sum = 0 count = 1 while count < 100:if count % 2 == 0:sum = sum - countelse:sum = sum + countcount += 1 print(sum)
?
#6、用戶登陸(三次機會重試) #input 心中有賬號,密碼 while i = 0 while i < 3:username = input('請輸入賬號:')password = int(input('請輸入密碼:'))if username == '咸魚哥' and password == 123:print('登錄成功')else:print('登錄失敗請重新登錄')i += 1?
#格式化輸出 # % s d # name = input('請輸入姓名') # age = input('請輸入年齡') # height = input('請輸入身高') # msg = "我叫%s,今年%s 身高 %s" %(name,age,height) # print(msg) """ name = input('請輸入姓名:') age = input('請輸入年齡:') job = input('請輸入工作:') hobbie = input('你的愛好:')msg = '''------------ info of %s ----------- Name : %s Age : %d job : %s Hobbie: %s ------------- end -----------------''' %(name,name,int(age),job,hobbie) print(msg) """ name = input('請輸入姓名') age = input('請輸入年齡') height = input('請輸入身高') msg = "我叫%s,今年%s 身高 %s 學習進度為3%%s" %(name,age,height) # %%轉譯% print(msg)?
count = 0 while count <= 5 :count += 1if count == 3:breakprint("Loop",count)else:print("循環正常執行完啦") print("-----out of while loop ------")?
- 太白金星老師
- 博客:https://www.cnblogs.com/jin-xin/
轉載于:https://www.cnblogs.com/LXL616/p/10622310.html
總結
以上是生活随笔為你收集整理的Python练习-2的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 图的并查集QuickFind类总结——C
- 下一篇: 超声波测距仪编程_基于单片机的超声波测距