2015-11-08 63 views
0
anwser=str(input("Do you need a new phone? ")) 

if answer== "no": 
    print ("You are now finished. ") 
else:  
    question1=str(input("Do you know what phone you want? ") 
    if question1== "no": 
     print("Research different phones and chose which pne you like best.") 
    else: 
     question2=str(input("Do you want to go on a contract? ") 
     if question2== "no": 
      question3=str(input("Do you have enought money to pay full price for your phone? ") 

問題出在哪裏?我該如何改進?它不斷出現語法錯誤,我不知道爲什麼。使用我的python代碼

+3

有幾個缺失的括號。你需要'foo = str(bar)',而不是'foo = str(bar'。 –

+0

儘管'str'完全沒有必要。 –

+0

語法錯誤告訴你什麼?另外,你應該指定什麼版本的Python,因爲2和3之間的語法略有不同。 – Keith

回答

3

你對你的問題缺少行右括號:

question1 = str(input("Do you know what phone you want? ") 

應該是:

question1 = str(input("Do you know what phone you want? ")) 

你也不需要輸入轉換爲字符串,因爲input()已經做那對你來說:

input([prompt]) 

如果提示參數存在,則會將其寫入標準輸出 ,而不會出現換行符。該函數然後從輸入中讀取一行, 將其轉換爲字符串(剝離尾隨換行符),並返回 。