我今天正在寫一些代碼,只是一個小腳本,它最多占用三個字符串,并把它們弄亂,顛倒它們,并將它們按不同的順序排列。當我嘗試運行我的代碼時,我收到一個無效的語法錯誤,但我真的不知道為什么。ammount = int(input("How many strings would you like to input? 1, 2 or 3?")# Getting user inputif ammount == 1: input1 = str(input("Please enter the first string"))elif ammount == 2: user_input_1 = str(input("Please enter the first string")) user_input_2 = str(input("Please enter the second string"))elif ammount == 3: user_input_1 = str(input("Please enter the first string")) user_input_2 = str(input("Please enter the second string")) user_input_3 = str(input("Please enter the third string"))
2 回答

翻翻過去那場雪
TA貢獻2065條經(jīng)驗 獲得超14個贊
)
轉(zhuǎn)換為 int 后,您錯過了關(guān)閉
ammount = int(input("How many strings would you like to input? 1, 2 or 3?"))

隔江千里
TA貢獻1906條經(jīng)驗 獲得超10個贊
您可能在 if 語句中收到錯誤消息,因為您)
在if ammount ==1:
語句之前的行尾缺少一個結(jié)束括號。錯誤落在 if 語句上,因為 python 解釋器認為您試圖將 if 語句放在轉(zhuǎn)換為 int 函數(shù)的內(nèi)部,而它不屬于那里
添加回答
舉報
0/150
提交
取消