當前位置:首頁 » 編程語言 » python基礎習題

python基礎習題

發布時間: 2023-02-26 00:48:40

python基礎題

(1)count = 0
(2)while count < 3:
(3) name = input()
(4) password = input()
(5) if name == 'Kate' and password == '666666':
(6) print("登錄成功!")
(7) break
(8) else:
(9) count += 1
(10) if count == 3:
(11) print("3次用戶名或者密碼均有誤!退出程序!")
程序開始執行:
(1):定義int類型變數count並為其賦初始值0,執行語句(2)。
(2):循環語句,若變數count>=3則跳出循環,程序結束。若count<3則進入循環,執行語句(3)。
(3):定義str類型變數name並調用python內置輸入函數input(),控制台等待輸入,假設輸入"Kate",執行語句(4)。
(4):定義str類型變數password並調用python內置輸入函數input(),控制台等待輸入,假設輸入"666666"。執行語句(5)
(5):判斷語句,若name變數的__str__()函數的返回值等於字元串'Kate'的__str__()函數的返回值且password變數__str__()函數的返回值等於字元串'666666'的__str__()函數的返回值則執行語句(6),否則執行語句(9),因假設中name變數的值為"Kate",password變數的值為"666666",故執行語句(6)

(6):調用內置輸出函數print(self, *args, sep=' ', end='\n', file=None),其中*args對應實參為「登錄成功!」,故輸出「登錄成功」。執行語句(7)

(7):break關鍵字,跳出循環,程序無後續代碼,程序結束。
(9):count變數的值等於count變數的值加1。執行語句(10)
(10):判斷count變數的值是否等於3,如果是執行語句(11),否則執行語句(2)
(11):調用內置輸出函數print(self, *args, sep=' ', end='\n', file=None),其中*args對應實參為「3次用戶名或密碼均有誤!退出程序」,故輸出「3次用戶名或密碼均有誤!退出程序」。執行語句(2),因count>=3,故執行完(2)後程序結束。

Ⅱ Python中基礎練習題

法一:利用set()函數的去重功能,去重後再使用list()函數將集合轉換為我們想要的列表
list1 = [11,22,33]
list2 = [22,33,44]
list3 = list(set(list1 + list2))
list3.sort()
print(list3)
-------------
法二:利用if和for,先遍歷list1所有元素追加到list3中,然後遍歷list2,條件判斷list2中當前元素是否在list3中,如果不在則追加到list3中
list1 = [11,22,33]
list2 = [22,33,44]
list3 = []
for ele1 in list1:
list3.append(ele1)
for ele2 in list2:
if ele2 not in list3:
list3.append(ele2)
print(list3)

Ⅲ python習題(演算法

這個就是循環2n次呀。先是讓x=x+c,在把c更新一下c=c+b,最後讓b=b+a,這就完成一次循環了。
不過你給的程序不完整。

Ⅳ Python練習題

1
print("hi, 「」「how are you」」」, I』m fine and you")

2
a, b= map(int, input().split())
r=a//b
m=a%b

熱點內容
懶人學編程 發布:2025-07-11 09:44:58 瀏覽:333
android命令行簽名 發布:2025-07-11 09:44:15 瀏覽:881
應用密碼怎麼取消密碼 發布:2025-07-11 09:28:33 瀏覽:797
pythonubuntumysql 發布:2025-07-11 09:23:47 瀏覽:531
硬碟屬於外部存儲器嗎 發布:2025-07-11 09:09:39 瀏覽:936
vs源碼查看 發布:2025-07-11 09:06:43 瀏覽:971
ip當前伺服器不可用是什麼意思 發布:2025-07-11 08:57:55 瀏覽:335
acfun如何緩存 發布:2025-07-11 08:48:12 瀏覽:3
我的世界伺服器tag 發布:2025-07-11 08:48:09 瀏覽:891
c語言設置 發布:2025-07-11 08:48:02 瀏覽:149