python模組 錯誤彙總

2021-08-13 03:28:53 字數 952 閱讀 9031

**如下:

num1 , num2 = eval(input(「請輸入被除數和除數 , 用逗號來分隔」))

這段**的原理是什麼???

解釋:

input函式接收到使用者輸入的兩個數字字串,eval函式則將字串的引號去掉,轉換成了數字型別,從而將這個表示式轉換成了多重賦值表示式,如:x , y = 1 , 2

錯誤**如下:

disroot = math.sqrt(deta)

root1 = (-b + disroot)/(2*a)

root2 = (-b - disroot)/(2*a)

print(「兩個不同的解為%.2f %.2f」 % root1 %root2)

執行時提示typeerror錯誤。

解釋:print()輸出格式不對,正確的格式應該為print(「兩個不同的解為%.2f %.2f」 %(root1 , root2))

說明:%與(root1 , root2)之間可以有空格,也可以沒有

**如下:

def drawdate(str):

i = 0

while str[i] != 「」:

drawdigit(int(str[i]) , i)

i += 1

while str[i] != 「」:

index_error : string index out of range

原因:如果輸入字串「201405」,那麼字串的下標到5,當i=6時,退出迴圈,不過由於str[6]已經超出了該字串的字串長度,所以系統會報錯

改進:可使用「for i in str」的形式來遍歷字串,如果需要標識i是字串中的第幾個字元,可單獨設定一整型變數a = 0,**如下:

a=0

for i in str:

drawdigit(int(i) , a)

a += 1

python 爬蟲 requests 錯誤彙總

原因分析 使用的 有問題 cannot connect to proxy 這是乙個https的不安全請求警告,解決方法就是將該警告忽略掉,忽略該警告就不會再提示了 from urllib3.exceptions import insecurerequestwarning from urllib3 i...

python安裝模組方法彙總

方法一 在 windows 系統下,只需要輸入命令 pip install requests 即可安裝。在 linux 系統下,只需要輸入命令 sudo pip install requests 即可安裝。注 關於python第三方庫的安裝最好少使用 easy install,因為 easy ins...

Python常用模組 庫彙總

點選模組 庫名字,檢視使用文件 npm常用模組彙總 node常用模組彙總 gulp常用外掛程式彙總 jquery常用外掛程式彙總 python常用模組 庫彙總 django django是乙個開放源 的web應用框架,由python寫成 flask flask 是乙個使用 python 編寫的輕量級...