2016-09-22 188 views
-3

我試圖寫一個計算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?") 

enter image description here

+2

算你'('和')'...你錯過了一對夫婦 –

+0

具體來說,你錯過了一個')'末的第二和第三行。第二行是錯誤實際存在的位置,但直到第三行才顯示,因爲直到那時它纔是語法錯誤。 –

回答

4

你找錯順序。你應該有int(input())不是input(int())

而且你還有比你應該少的)。檢查每一個打開支架有一個關閉一個

1

你有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?")) 
0

避免使用輸入()和使用的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?")) 
+0

爲什麼raw_input更好? – Yjell

+0

raw_input()允許用戶輸入字符作爲字符串,並且不會給用戶完全的權力,而只會將這些字符串輸入到系統中。出於安全原因,只使用raw_input。 Input()會嘗試將輸入作爲python命令運行。該功能已被Python 3帶走,但仍在Python 2.7中。 – CasperTN