我試圖寫一個計算BMI的程序,方法是詢問人的體重(以千克爲單位)和身高(以米爲單位)。爲什麼我在這裏得到一個無效的語法錯誤?無效的語法錯誤
units = input("What units would you like to use? Enter I for Imperial or M for Metric")
weight = input(int("what's your weight?")
height = input(int("what's your height?")
我試圖寫一個計算BMI的程序,方法是詢問人的體重(以千克爲單位)和身高(以米爲單位)。爲什麼我在這裏得到一個無效的語法錯誤?無效的語法錯誤
units = input("What units would you like to use? Enter I for Imperial or M for Metric")
weight = input(int("what's your weight?")
height = input(int("what's your height?")
你找錯順序。你應該有int(input())
不是input(int())
而且你還有比你應該少的)
。檢查每一個打開支架有一個關閉一個
你有int和輸入錯誤的順序,做忘記了右括號:
units = input("What units would you like to use? Enter I for Imperial or M
for Metric")
weight = int(input("what's your weight?"))
height = int(input("what's your height?"))
避免使用輸入()和使用的raw_input()代替。你也把int()放在錯誤的地方。
您的代碼應該是這個樣子:
units = raw_input('What units would you like to use?....')
weight = int(raw_input("what's your weight?"))
height = int(raw_input("what's your height?"))
算你'('和')'...你錯過了一對夫婦 –
具體來說,你錯過了一個')'末的第二和第三行。第二行是錯誤實際存在的位置,但直到第三行才顯示,因爲直到那時它纔是語法錯誤。 –